我收到了以下错误:
com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String
at com.google.android.gms.internal.zzbtg.zzaF(Unknown Source)
at com.google.android.gms.internal.zzbtg.zzb(Unknown Source)
at com.google.android.gms.internal.zzbtg.zza(Unknown Source)
at com.google.android.gms.internal.zzbtg.zzb(Unknown Source)
at com.google.android.gms.internal.zzbtg$zza.zze(Unknown Source)
at com.google.android.gms.internal.zzbtg$zza.zzaH(Unknown Source)
at com.google.android.gms.internal.zzbtg.zze(Unknown Source)
at com.google.android.gms.internal.zzbtg.zzb(Unknown Source)
at com.google.android.gms.internal.zzbtg.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at in.thegeekybaniya.q_time.EventFrag$2.onDataChange(EventFrag.java:81)
at com.google.android.gms.internal.zzbpx.zza(Unknown Source)
at com.google.android.gms.internal.zzbqx.zzZS(Unknown Source)
at com.google.android.gms.internal.zzbra$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
目前:
mChild.addValueEventListener(new ValueEventListener() {
public static final String TAG = "Members";
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child :
dataSnapshot.getChildren()) {
eventArrayList.add(child.getValue(Event.class));
Log.d(TAG, "onDataChange: " + eventArrayList.toString());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
我的数据库如下所示:
这是我的Event类:
package in.thegeekybaniya.q_time;
import java.util.ArrayList;
public class Event {
int likes, dislikes;
String name, key;
ArrayList<String> likeList, dislikeList;
int report;
public Event(String name) {
this.name = name;
this.likes = 0;
this.dislikes = 0;
this.report = 0;
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("abcd");
this.likeList = arrayList;
this.dislikeList = arrayList;
}
public Event(int likes, int dislikes, String name, String key, ArrayList<String> likeList, ArrayList<String> dislikeList, int report) {
this.likes = likes;
this.dislikes = dislikes;
this.name = name;
this.key = key;
this.likeList = likeList;
this.dislikeList = dislikeList;
this.report = report;
}
public Event() {
}
public void dislikePressedFirst() {
this.dislikes += 1;
}
public void likePressed() {
this.likes += 1;
this.dislikes -= 1;
}
public void dislikePressed() {
this.dislikes += 1;
this.likes -= 1;
}
public void likePressedFirst() {
this.likes += 1;
}
public int getLikes() {
return likes;
}
public void setLikes(int likes) {
this.likes = likes;
}
public int getDislikes() {
return dislikes;
}
public void setDislikes(int dislikes) {
this.dislikes = dislikes;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public ArrayList<String> getLikeList() {
return likeList;
}
public void setLikeList(ArrayList<String> likeList) {
this.likeList = likeList;
}
@Override
public String toString() {
return "Event{" +
"likes=" + likes +
", dislikes=" + dislikes +
", name='" + name + '\'' +
", key='" + key + '\'' +
", likeList=" + likeList +
", dislikeList=" + dislikeList +
", report=" + report +
'}';
}
public ArrayList<String> getDislikeList() {
return dislikeList;
}
public void setDislikeList(ArrayList<String> dislikeList) {
this.dislikeList = dislikeList;
}
public int getReport() {
return report;
}
public void setReport(int report) {
this.report = report;
}
}
这是一张快照:
请帮忙。
抱歉早些时候我从错误的片段粘贴了代码。请原谅。
我的一个朋友建议FireBase有一个处理整数的硬时间,并且每次将整数转换为字符串并解析它们是个好主意。
更新(19/5/17) - 如果我从类中删除int报告(并编辑getter setter和相关功能),一切正常,这是数据成员的一些严重组合。