gpt4 book ai didi

java - 获取 "com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String"

转载 作者:行者123 更新时间:2023-12-02 04:14:14 26 4
gpt4 key购买 nike

当我想显示通知区域时出现异常,但我不知道问题出在哪里。

通知 fragment

package com.developer.fireone.finga.Fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.developer.fireone.finga.Adapter.NotificationAdapter;
import com.developer.fireone.finga.Model.Chat;
import com.developer.fireone.finga.Model.Notification;
import com.developer.fireone.finga.R;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;


public class NotificationFragment extends Fragment {

private RecyclerView recyclerView;
private NotificationAdapter notificationAdapter;
private List<Notification> notificationList;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_notification, container, false);

recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(linearLayoutManager);

notificationList= new ArrayList<>();
notificationAdapter = new NotificationAdapter(getContext(), notificationList);
recyclerView.setAdapter(notificationAdapter);

readNotifications();

return view;
}

private void readNotifications() {

FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Notifications").child(firebaseUser.getUid());
reference.keepSynced(true);
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
notificationList.clear();
for(DataSnapshot snapshot:dataSnapshot.getChildren()){
Notification notif=snapshot.getValue(Notification.class); //exception
notificationList.add(notif);
}

Collections.reverse(notificationList);
notificationAdapter.notifyDataSetChanged();
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}

}

通知(模型)

package com.developer.fireone.finga.Model;

/**
* Created by user on 20/12/2018.
*/

public class Notification {

private String userid;
private String text;
private String postid;
private boolean ispost;

public Notification() {
}

public Notification(String userid, String text, String postid, boolean ispost) {
this.userid = userid;
this.text = text;
this.postid = postid;
this.ispost = ispost;
}


public String getUserid() {
return userid;
}

public void setUserid(String userid) {
this.userid = userid;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public String getPostid() {
return postid;
}

public void setPostid(String postid) {
this.postid = postid;
}

public boolean isIspost() {
return ispost;
}

public void setIspost(boolean ispost) {
this.ispost = ispost;
}

}

这是 Firebase 中的通知:

image in firebase

最佳答案

可能在通知模型中,您的变量之一很长,但您将其声明为字符串例如

    private String userid;
private String text;
private String postid;

关于java - 获取 "com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56670161/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com