我正在尝试将信息插入Firebase数据库,我收到了上述错误。
完整的堆栈跟踪:
04-16 02:42:14.218 6214-6214/com.example.or.dancers E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.or.dancers, PID: 6214
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.Long to type com.example.or.dancers.Info
at com.google.android.gms.internal.zzbqi.zze(Unknown Source)
at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
at com.google.android.gms.internal.zzbqi.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.example.or.dancers.Settings$1.onDataChange(Settings.java:187)
at com.google.android.gms.internal.zzbmz.zza(Unknown Source)
at com.google.android.gms.internal.zzbnz.zzYj(Unknown Source)
at com.google.android.gms.internal.zzboc$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:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
我的对象模型:
package com.example.or.dancers;
public class Info {
public String key;
public String infoName;
public int data;
public Info() {
}
public Info(String key, String name, int data) {
this.key = key;
this.infoName = name;
this.data = data;
}
}
retrieveData函数:
public void retrieveData() {
database.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()) {
Info d = data.getValue(Info.class);
if(d.key.equals(info.key)){
info =d;
return;
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}//retrieveData function.
我坚持这一点,因此我无法继续前进。 任何帮助将不胜感激。
获得价值:
public Object getValue() {
return this.zzbXv.zzUY().getValue();
}
public Object getValue(boolean var1) {
return this.zzbXv.zzUY().getValue(var1);
}
public <T> T getValue(Class<T> var1) {
Object var2 = this.zzbXv.zzUY().getValue();
return zzbqi.zza(var2, var1);
}
public <T> T getValue(GenericTypeIndicator<T> var1) {
Object var2 = this.zzbXv.zzUY().getValue();
return zzbqi.zza(var2, var1);
}
答案 0 :(得分:0)
我认为您应该调试以查找传递给Info对象的值。由于此错误与将Long转换为Info:
相关com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.Long to type com.example.or.dancers.Info