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

标签 android firebase google-cloud-firestore

我收到这个运行时错误,我不明白它背后的原因。

com.google.firebase.firestore.FirebaseFirestoreException:获取文档失败,因为客户端离线。

下面是我的 Activity 中尝试从云 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());
            }
        }
    });

对此我能做些什么吗?

最佳答案

发生这种情况是因为在任务完成时触发了 OnCompleteListener,它要么失败,要么成功。为避免该错误,您可以使用单独的 OnSuccessListenerOnFailureListener

OnSuccessListener在任务成功时被调用,但是如果出现上述错误,OnFailureListener会被触发,你可以在onFailure()中处理错误 监听器的方法。

快乐编码:)

关于android - com.google.firebase.firestore.FirebaseFirestoreException : Failed to get document because the client is offline. Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46620957/

相关文章:

Firebase Firestore 文档更改历史记录(如事件日志/每个文档更改的历史记录)

android - 使用 Gluon 在 APK META-INF/INDEX.LIST 中复制的重复文件

java - 将 xml 字符串数组中的项目添加到 fragment 内的回收器 View 中

ios - 读取 firebase 数据库并存储在字符串变量中失败

android - Android Studio问题与Gradle中的Firebase ui存储

java - 如何在应用程序启动时使用 recyclerview 加载 fragment ?

Android 应用程序(Samsung Galaxy Tab,2.2)*有时*不写入数据库

android - 如何在弹出窗口中打开 Activity ?

ios - Firebase 使用电子邮件、密码、显示名称和照片网址创建用户

java - 如何读取/更新存储在 map 中的值,然后在 Cloud Firestore 中的数组中?