简体   繁体   English

Firebase 错误:“反序列化时需要一个列表,但得到一个 class java.util.HashMap”

[英]Firebase Error: "Expected a List while deserializing, but got a class java.util.HashMap"

I had a structure in my database that worked perfectly, but then I add the following node to my database and since then I'm getting this error.我的数据库中有一个运行良好的结构,但后来我将以下节点添加到我的数据库中,从那以后我收到了这个错误。 If I delete the "commentList" node it works again.如果我删除“commentList”节点,它会再次起作用。 Why would it change from a list to a Hashmap?为什么它会从列表变为 Hashmap?

My db structure.我的数据库结构。 It worked before adding that "commentList"在添加“commentList”之前它起作用了

The code responsible for this: code负责此的代码:代码

Here the log error:这里的日志错误:

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)

What is causing this and how would I fix this?是什么原因造成的,我将如何解决这个问题?

You must be sure that the firebase object is array, not map, like that: firebase 您必须确保firebase对象是数组,而不是map,如下所示: firebase

I've had the same problem, the solution was check the type of object, directly in firebase database and change Map(HashMap) to Array(List) 我有同样的问题,解决方案是直接在firebase数据库中检查对象的类型,然后将Map(HashMap)更改为Array(List)

I know it's a bit late, but I'll post it for others who encounter the same issue.我知道这有点晚了,但我会为遇到同样问题的其他人发布它。 Firebase real-time database does not store collections in lists but HashMap s. Firebase 实时数据库不在列表中存储 collections 但HashMap s。 Your model property should be more like this:您的 model 属性应该更像这样:

var commentList: HashMap<String, String>? = null

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 反序列化时需要一个列表,但得到了一个类 java.util.HashMap - Expected a List while deserializing, but got a class java.util.HashMap Firebase“无法将 java.util.HashMap 类型的值转换为 int” - Firebase "Failed to convert a value of type java.util.HashMap to int" 当我尝试从 firebase 检索数据到 viewpager2 时,无法将 java.util.HashMap 类型的值转换为字符串错误 - Failed to convert value of type java.util.HashMap to String error when I'm trying to retrieve data from firebase to viewpager2 语法错误:应为“(”或“,”或关键字 SELECT 但脚本结束 - Syntax error: Expected "(" or "," or keyword SELECT but got end of script class 的属性类型,用于从 firebase 中检索列表 - Type of attribute of class for retrieving list from firebase Firebase onSnapshot 反应错误,“预期类型 'bc',但它是:自定义 he 对象” - Firebase onSnapshot in react error, "Expected type 'bc', but it was: a custom he object" 使用 with 子句时出错我收到消息“语法错误:预期的关键字 AS 但在 [7:14] 得到了“(” - Error using the with clause I received message " Syntax error: Expected keyword AS but got "(" at [7:14]" pandas.to_gbq() 返回“ArrowTypeError: Expected bytes, got a 'datetime.date' object”错误 - pandas.to_gbq() returning "ArrowTypeError: Expected bytes, got a 'datetime.date' object" error 当我将 firebase 与节点 js 连接时。 我得到了这个错误。 我如何修复此错误并将 firebase 连接到 node express 项目 - when I connecting firebase with node js. I got this error. how I fix this error and connect firebase to node express project 错误:无法在 firebase 中列出 (ProjectName) 的函数 - Error: Failed to list functions for (ProjectName) in firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM