Firebase setvalue DatabaseException:无法解析具有类 class 的节点

Hun*_*yen 1 android firebase firebase-realtime-database

我看过其他帖子,但似乎没有一个解决方案适合我的问题。错误出在方法上FirebaseRef.setValue()

\n\n

我正在尝试将数据保存到Firebase server. 起初我认为错误是因为我尝试将数据保存为自定义对象,然后我尝试将其保存为基本哈希(我按照链接中的教程进行操作)

\n\n
protected Boolean doInBackground(Void... params) {\n            // Database Connection, if no connection or what not, exception will be here\n            mDatabase = FirebaseDatabase.getInstance().getReference();\n            Log.d(DBTAG, mDatabase.toString());\n\n            // \'child database\'\n            mBooksDatabase = mDatabase.child("books");\n            mCurrentUser = mDatabase.child("users").child(mUserEmail);\n\n            // address to upload the book, later we can call newBookRef.getKey() to get the ID\n            // and use the ID to indicate the relationship between the owner and the book\n            final DatabaseReference newBookRef = mBooksDatabase.push();\n            try {\n                Map<String, String> mBookTest = new HashMap<String, String>();\n                mBookTest.put("ISBN", "9781566199094");\n                mBookTest.put("title", "Book of Love");\n                newBookRef.setValue(mBookTest, new Firebase.CompletionListener() {\n                    @Override\n                    public void onComplete(FirebaseError firebaseError, Firebase firebase) {\n                        if (firebaseError != null) {\n                            Log.e(DBTAG, "Data could not be saved. " + firebaseError.getMessage());\n                        } else {\n                            Log.d(DBTAG, "Data saved successfully.");\n                            // update the \'owns\' list in user\'s data\n                            final String bookRef = newBookRef.getKey();\n                            mCurrentUser.child("owns").child(bookRef).setValue("1");\n                            //TODO: we can use this to count how many of the same books an user has\n                        }\n                    }\n                });\n            } catch (DatabaseException e){\n                Log.e(DBTAG, "Error occurred", e);\n            }\n            // if owner is desired in book, we can modify this part\n\n            return true;\n        }\n
Run Code Online (Sandbox Code Playgroud)\n\n

错误信息:

\n\n
09-26 20:37:12.631 5091-5399/bookjobs.bookjobs D/DB\xc2\xa0in\xc2\xa0BookController: https://bookjobs-6c56f.firebaseio.com\n09-26 20:37:12.641 5091-5399/bookjobs.bookjobs E/DB\xc2\xa0in\xc2\xa0BookController: Error occurred\n                                                                       com.google.firebase.database.DatabaseException: Failed to parse node with class class bookjobs.bookjobs.BookController$UploadBookTask$1\n                                                                           at com.google.android.gms.internal.zzakk.zza(Unknown Source)\n                                                                           at com.google.android.gms.internal.zzakk.zzbq(Unknown Source)\n                                                                           at com.google.android.gms.internal.zzakn.zzbr(Unknown Source)\n                                                                           at com.google.firebase.database.DatabaseReference.setValue(Unknown Source)\n                                                                           at bookjobs.bookjobs.BookController$UploadBookTask.doInBackground(BookController.java:59)\n                                                                           at bookjobs.bookjobs.BookController$UploadBookTask.doInBackground(BookController.java:30)\n                                                                           at android.os.AsyncTask$2.call(AsyncTask.java:295)\n                                                                           at java.util.concurrent.FutureTask.run(FutureTask.java:237)\n                                                                           at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)\n                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)\n                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)\n                                                                           at java.lang.Thread.run(Thread.java:818)\n09-26 20:37:15.831 5091-5169/bookjobs.bookjobs W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.\n
Run Code Online (Sandbox Code Playgroud)\n

Bob*_*der 5

您调用的完成侦听器setValue()来自旧版 2.xx SDK:Firebase.CompletionListener()。您必须使用新的 9.xx SDK 中的完成侦听器DatabaseReference.CompletionListener()

这两个 SDK 不兼容。您应该专门使用新的 SDK。更新您的build.gradle以删除:

compile 'com.firebase:firebase-client-android:2.x.x'
Run Code Online (Sandbox Code Playgroud)

请参阅升级指南了解更多详细信息。