I am getting a Null Object Reference
and the app crashes when I sign out.
Code:
//Get Comments Count
firebaseFirestore.collection("Posts/" + postId + "/Comments").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
if (!documentSnapshots.isEmpty())
{
int count = documentSnapshots.size();
holder.updateCommentsCount(count);
}
else if(documentSnapshots.isEmpty())
{
holder.updateCommentsCount(0);
}
}
});
Error:
Attempt to invoke virtual method 'boolean com.google.firebase.firestore.QuerySnapshot.isEmpty()' on a null object reference