gpt4 book ai didi

java - Android Firebase 2.4 IllegalStateException 使用新的 ref.updateChildren()

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:02:11 24 4
gpt4 key购买 nike

使用 Firebase 2.4 时 ref.updateChildren()使用 HashMap,而不是 HashMap<String, Object> (例如 HashMap<String, User>)获取 IllegalStateException。

> 09-29 18:03:21.680: E/AndroidRuntime(6863): FATAL EXCEPTION: main
> 09-29 18:03:21.680: E/AndroidRuntime(6863): Process:
> com.xxx.xxx.xxx, PID: 6863 09-29
> 18:03:21.680: E/AndroidRuntime(6863): java.lang.IllegalStateException:
> Could not execute method of the activity 09-29 18:03:21.680:
> E/AndroidRuntime(6863): at
> android.view.View$1.onClick(View.java:4035) 09-29 18:03:21.680:
> E/AndroidRuntime(6863): at
> android.view.View.performClick(View.java:4881) 09-29 18:03:21.680:
> E/AndroidRuntime(6863): at
> android.view.View$PerformClick.run(View.java:19592) 09-29
> 18:03:21.680: E/AndroidRuntime(6863): at
> android.os.Handler.handleCallback(Handler.java:733) 09-29
> 18:03:21.680: E/AndroidRuntime(6863): at
> android.os.Handler.dispatchMessage(Handler.java:95) 09-29
> 18:03:21.680: E/AndroidRuntime(6863): at
> android.os.Looper.loop(Looper.java:146) 09-29 18:03:21.680:
> E/AndroidRuntime(6863): at
> android.app.ActivityThread.main(ActivityThread.java:5756) 09-29
> 18:03:21.680: E/AndroidRuntime(6863): at
> java.lang.reflect.Method.invokeNative(Native Method) 09-29
> 18:03:21.680: E/AndroidRuntime(6863): at
> java.lang.reflect.Method.invoke(Method.java:515) 09-29 18:03:21.680:
> E/AndroidRuntime(6863): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
> 09-29 18:03:21.680: E/AndroidRuntime(6863): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 09-29
> 18:03:21.680: E/AndroidRuntime(6863): at
> dalvik.system.NativeStart.main(Native Method) 09-29 18:03:21.680:
> E/AndroidRuntime(6863): Caused by:
> java.lang.reflect.InvocationTargetException 09-29 18:03:21.680:
> E/AndroidRuntime(6863): at
> java.lang.reflect.Method.invokeNative(Native Method) 09-29
> 18:03:21.680: E/AndroidRuntime(6863): at
> java.lang.reflect.Method.invoke(Method.java:515) 09-29 18:03:21.680:
> E/AndroidRuntime(6863): at
> android.view.View$1.onClick(View.java:4030) 09-29 18:03:21.680:
> E/AndroidRuntime(6863): ... 11 more 09-29 18:03:21.680:
> E/AndroidRuntime(6863): Caused by:
> com.firebase.client.FirebaseException: Failed to parse node with class
> class com.xxx.xxx.xxx.User 09-29
> 18:03:21.680: E/AndroidRuntime(6863): at
> com.firebase.client.snapshot.NodeUtilities.NodeFromJSON(NodeUtilities.java:84)
> 09-29 18:03:21.680: E/AndroidRuntime(6863): at
> com.firebase.client.snapshot.NodeUtilities.NodeFromJSON(NodeUtilities.java:12)
> 09-29 18:03:21.680: E/AndroidRuntime(6863): at
> com.firebase.client.utilities.Validation.parseAndValidateUpdate(Validation.java:127)
> 09-29 18:03:21.680: E/AndroidRuntime(6863): at
> com.firebase.client.Firebase.updateChildren(Firebase.java:438)

编辑:

有没有办法传递像 HashMap<String, User> 这样的自定义 HashMap?至 ref.updateChildren()

最佳答案

关于你的最后一个问题:

Is there a way to pass custom HashMap like HashMap to ref.updateChildren() ?

适用于 Android/Java 的 Firebase SDK 不支持直接将 POJO(例如您的 User 类)传递到 updateChildren()

但是您可以做的是将 POJO 转换为 Map :

Map<String, Object> userMap = new ObjectMapper().convertValue(user, Map.class);

然后您可以将值映射放入您传递给 updateChildren() 的值中:

updates.put("users/"+uid, userMap);
updates.put("lists/"+uid+"/mine, "value");

ref.updateChildren(updates);

关于java - Android Firebase 2.4 IllegalStateException 使用新的 ref.updateChildren(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32848024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com