2017-10-07 37 views
8

我得到這個運行時錯誤,我不明白它背後的原因。com.google.firebase.firestore.FirebaseFirestoreException:由於客戶端處於脫機狀態而無法獲取文檔。 Android

com.google.firebase.firestore.FirebaseFirestoreException: Failed to get document because the client is offline.

下面是在我的活動,試圖從雲公司的FireStore

DocumentReference docRef = db.collection("room-id-1").document("participan-name-1"); 
    docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { 
     @Override 
     public void onComplete(@NonNull Task<DocumentSnapshot> task) { 
      if (task.isSuccessful()) { 
       DocumentSnapshot document = task.getResult(); 
       if (document != null) { 
        Log.d(TAG, "DocumentSnapshot data: " + task.getResult().getData()); 
        userData.registerUserToHotspot(roomId_str, participantName_str); 
       } else { 
        Log.d(TAG, "No such document"); 
       } 
      } else { 
       Log.d(TAG, "get failed with ", task.getException()); 
      } 
     } 
    }); 

獲取數據的代碼有什麼我可以做這件事?

+0

我在同樣的問題。 FirebaseFirestoreException.Code是「UNAVAILABLE」。這意味着「該服務目前不可用,這很可能是暫時的情況,可能會通過退避重試來糾正」。我不知道現在該怎麼辦...... – yoonhok

+1

同樣的問題,有些解決方案? – Daniel

+0

我看到,這個錯誤是因爲當你沒有連接或客戶端不可用時,我覺得有問題,因爲我得到這個錯誤與強制關閉,即使我是,管理異常在相同方式喲。而更有趣的是,在恢復我的互聯網之後,錯誤總是在第一次查詢時發生。例如:'飛行模式>不做任何事>關閉飛行模式>等待20s>查詢東西>因爲客戶端處於脫機狀態而無法獲取文檔.' 這是API的錯誤嗎?這只是發生在Android,而不是IOS –

回答

0

如果你正在使用rxjava那麼wiil簡單趕上拋出這樣:

RxFirestore.getDocument(FirebaseFirestore.getInstance() 
    .collection("info") 
    .document("app")) 
    .subscribeOn(Schedulers.io()) 
    .subscribe(snapshot -> { 

    }, throwable -> Timber.e(throwable)) 

否則試圖以某種方式捕獲它的承諾或/和try-catch塊

相關問題