2016-09-26 3 views
0

다른 게시물을 보았지만 문제가 해결되지 않았습니다. 메서드에서 오류가 발생했습니다. FirebaseRef.setValue()Firebase setvalue DatabaseException : 클래스 클래스로 노드를 구문 분석하지 못했습니다.

데이터를 Firebase server에 저장하려고합니다.

: 나는 사용자 정의 개체로 데이터를 저장하려고하기 때문에 처음에는 내가 기본 해시로 저장하려고 다음 오류라고 생각

protected Boolean doInBackground(Void... params) { 
      // Database Connection, if no connection or what not, exception will be here 
      mDatabase = FirebaseDatabase.getInstance().getReference(); 
      Log.d(DBTAG, mDatabase.toString()); 

      // 'child database' 
      mBooksDatabase = mDatabase.child("books"); 
      mCurrentUser = mDatabase.child("users").child(mUserEmail); 

      // address to upload the book, later we can call newBookRef.getKey() to get the ID 
      // and use the ID to indicate the relationship between the owner and the book 
      final DatabaseReference newBookRef = mBooksDatabase.push(); 
      try { 
       Map<String, String> mBookTest = new HashMap<String, String>(); 
       mBookTest.put("ISBN", "9781566199094"); 
       mBookTest.put("title", "Book of Love"); 
       newBookRef.setValue(mBookTest, new Firebase.CompletionListener() { 
        @Override 
        public void onComplete(FirebaseError firebaseError, Firebase firebase) { 
         if (firebaseError != null) { 
          Log.e(DBTAG, "Data could not be saved. " + firebaseError.getMessage()); 
         } else { 
          Log.d(DBTAG, "Data saved successfully."); 
          // update the 'owns' list in user's data 
          final String bookRef = newBookRef.getKey(); 
          mCurrentUser.child("owns").child(bookRef).setValue("1"); 
          //TODO: we can use this to count how many of the same books an user has 
         } 
        } 
       }); 
      } catch (DatabaseException e){ 
       Log.e(DBTAG, "Error occurred", e); 
      } 
      // if owner is desired in book, we can modify this part 

      return true; 
     } 

오류 메시지 (나는 this 링크에서 튜토리얼을 따라)

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

Firebase 작업을 수행하는 데 AsyncTack을 사용할 필요가 없으며 Firebase가 이미 최적화되어 있고 모든 네트워크 관련 작업이 백그라운드 스레드에서 실행됩니다. –

+0

HashMap을 작성하는 오류 메시지를 어떻게 얻을 수 있는지 잘 모르겠습니다. 코드 샘플에서 올바른지 다시 한번 확인할 수 있습니까? –

답변

4

setValue()을 호출하는 완료 수신기는 기존 2.xx SDK의 것입니다 : Firebase.CompletionListener()입니다. 새로운 9.x.x SDK의 완성 수신기 인 DatabaseReference.CompletionListener()을 사용해야합니다.

두 SDK는 호환되지 않습니다. 새 SDK 만 사용해야합니다. 당신의 build.gradle 제거 업데이트 :

compile 'com.firebase:firebase-client-android:2.x.x' 

은 자세한 내용은 Upgrade Guide를 참조하십시오.

+0

좋은 캐치 qbix! 당황스럽게도 마이클과 나 자신은 그것을 간과했다. 다른 Firebase 개발자를 도와 주셔서 감사합니다! –

관련 문제