Firebase错误:“反序列化时出现了预期的列表,但有一个类java.util.HashMap”

时间:2018-12-30 17:37:15

标签: java android arraylist firebase-realtime-database hashmap

我的数据库中的结构运行良好,但随后将以下节点添加到数据库中,此后出现此错误。如果删除“ commentList”节点,它将再次起作用。为什么将其从列表更改为Hashmap?

My db structure. It worked before adding that "commentList"

对此负责的代码: code

这里是日志错误:

com.google.firebase.database.DatabaseException: Expected a List while deserializing, but got a class java.util.HashMap
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToParameterizedType(com.google.firebase:firebase-database@@16.0.5:233)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@16.0.5:176)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$100(com.google.firebase:firebase-database@@16.0.5:47)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.5:580)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.5:550)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@16.0.5:420)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.0.5:214)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@16.0.5:178)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$100(com.google.firebase:firebase-database@@16.0.5:47)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.5:580)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.5:550)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@16.0.5:420)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.0.5:214)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@16.0.5:178)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToParameterizedType(com.google.firebase:firebase-database@@16.0.5:247)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@16.0.5:176)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@16.0.5:101)
    at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@16.0.5:239)
    at com.example.xandi.whib.MainActivity$3.onDataChange(MainActivity.java:236)
    at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@16.0.5:75)
    at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@16.0.5:63)
    at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@16.0.5:55)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6626)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

是什么原因造成的,我该如何解决?

1 个答案:

答案 0 :(得分:0)

您必须确保firebase对象是数组,而不是map,如下所示: firebase

我遇到了同样的问题,解决方案是直接在firebase数据库中检查对象的类型,然后将Map(HashMap)更改为Array(List)