我有一个方法可以返回事件对象的 ArrayList 。我正在使用将存储在firebase中的数据映射到 POJO 的方法。从调试开始,映射是正确的,我将对象添加到 ArrayList jsonString ,代码在退出for循环时崩溃。
它给出错误:
com.google.firebase.database.DatabaseException: Expected a List while deserializing, but got a class java.util.HashMap
。
我没有添加很多代码,因为这个方法是独立的。
public ArrayList<Event> getJsonString(){
final ArrayList<Event> jsonString = new ArrayList();
mFirebaseDatabaseReference = database.getInstance().getReference(MESSAGES_CHILD);
//mFirebaseDatabaseReference.child(MESSAGES_CHILD);
mFirebaseDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot eventSnapshot:dataSnapshot.getChildren()){
Event event = eventSnapshot.getValue(Event.class);
jsonString.add(event);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return jsonString;
}
stacktrace:
07-25 21:21:23.178 3037-3079/com.firstintel.zimnights E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.firstintel.zimnights-1/base.apk"],nativeLibraryDirectories=[/data/app/com.firstintel.zimnights-1/lib/x86_64, /vendor/lib64, /system/lib64]]
07-25 21:21:23.191 3037-3079/com.firstintel.zimnights E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.firstintel.zimnights-1/base.apk"],nativeLibraryDirectories=[/data/app/com.firstintel.zimnights-1/lib/x86_64, /vendor/lib64, /system/lib64]]
07-25 21:21:27.313 3037-3095/com.firstintel.zimnights E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f758c234b90
07-25 21:21:27.415 3037-3095/com.firstintel.zimnights E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f758c235530
07-25 21:21:28.228 3037-3037/com.firstintel.zimnights E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.firstintel.zimnights, PID: 3037
com.google.firebase.database.DatabaseException: Expected a List while deserializing, but got a class java.util.HashMap
at com.google.android.gms.internal.zzaix.zza(Unknown Source)
at com.google.android.gms.internal.zzaix.zza(Unknown Source)
at com.google.android.gms.internal.zzaix.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.firstintel.zimnights.EventFragment$1.onDataChange(EventFragment.java:146)
at com.google.android.gms.internal.zzafp.zza(Unknown Source)
at com.google.android.gms.internal.zzagp.zzSu(Unknown Source)
at com.google.android.gms.internal.zzags$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:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
答案 0 :(得分:-2)
管理做一个变通方法,而不是返回ArrayList,我只是在 getJsonString() 中调用了适配器,然后我在 的OnCreate() 即可。 Voila完美的工作会弄清楚哪种设计模式,任何人都知道吗?