Firebase 2.4 ref.updateChildren()
をHashMapで使用する場合、HashMap<String, Object>
(例:HashMap<String, User>
)以外はIllegalStateExceptionを受け取ります。Android Firebase 2.4 IllegalStateException new ref.updateChildren()を使用しています
> 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:
はref.updateChildren()
にカスタムHashMapのHashMap<String, User>
のように合格する方法はありますか?
Map<String, String> newPost = new HashMap<String, String>();
newPost.put("title", "New Post");
newPost.put("content", "Here is my new post!");
そしてカスタム・データ・モデルの代わりにそれを置く::1は、このような再書き込みカスタム構造にあり、この問題を回避するためにOfficial Firebase Blogからのコードスニペットのように
ありがとう、フランク!このアプローチは、ユーザーをフィールドごとにマップフィールドに変換するよりもはるかに簡潔です。 –