android – Firestore Failed to get document because the client is offline-ThrowExceptions

Exception or error:

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();

                    }

                }
            });
How to solve:

Just change your mobile data from sim1 to sim2 or vice versa. It will work.
If you are connected from WiFi then turn off your WiFi and turn on mobile data plan.

Once it run, you can roll back to your previous settings (of your mobile phone).

Leave a Reply

Your email address will not be published. Required fields are marked *