When using Firebase 2.4 ref.updateChildren()
with HashMap, other than HashMap<String, Object>
(e.g. HashMap<String, User>
) getting the 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)
EDIT:
Is there a way to pass custom HashMap like HashMap<String, User>
to ref.updateChildren()
?
On your last question:
The Firebase SDK for Android/Java doesn't support directly passing POJOs (like your
User
class) intoupdateChildren()
.But what you can do is convert the POJO into a
Map
with:Then you can put the map of values into the values that you're passing into
updateChildren()
:As in the code snippet from the Official Firebase Blog to avoid this issue one has to re-write custom structure like this:
And then put it instead of custom data model:
Using custom data model instead of
newPost
causes IllegalStateException.