Dan Jhay
Dan Jhay

Reputation: 150

Firestore Failed to get document because the client is offline

I'm getting an error while offline.

I already set the Persistence to True and getting some cached data while offline, but there is one function that gives me this offline error. The logcat point me on task.getResult().exists().

I don't know what to do, can anyone help me?

ERROR: com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.firestore.FirebaseFirestoreException: Failed to get document because the client is offline.

firebaseFirestore.collection("Posts/" + blogPostId + "/Likes").document(currentUserId).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                @Override
                public void onComplete(@NonNull Task<DocumentSnapshot> task) {

                    if(!task.getResult().exists()){ //I GET ERROR HERE

                        Map<String, Object> likesMap = new HashMap<>();
                        likesMap.put("timestamp", FieldValue.serverTimestamp());

                        firebaseFirestore.collection("Posts/" + blogPostId + "/Likes").document(currentUserId).set(likesMap);

                    } else {

                        firebaseFirestore.collection("Posts/" + blogPostId + "/Likes").document(currentUserId).delete();

                    }

                }
            });

Upvotes: 1

Views: 4664

Answers (1)

Ishan
Ishan

Reputation: 82

for me in flutter android app development process

  • Open android studio emulator and choose wipe data
  • and run again

note: I know only for android.

Upvotes: 1

Related Questions