My app is getting some errors whenever I click the signout button. I suspect that this causes by the authentication.signout()
.
This is the error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.demo.finalssuncrestbank, PID: 17982
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.firestore.DocumentSnapshot.getString(java.lang.String)' on a null object reference
at com.demo.finalssuncrestbank.UserProfile$1.onEvent(UserProfile.java:52)
at com.demo.finalssuncrestbank.UserProfile$1.onEvent(UserProfile.java:49)
at com.google.firebase.firestore.DocumentReference.lambda$addSnapshotListenerInternal$2(DocumentReference.java:483)
at com.google.firebase.firestore.DocumentReference$$Lambda$3.onEvent(Unknown Source:6)
at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0(AsyncEventListener.java:42)
at com.google.firebase.firestore.core.AsyncEventListener$$Lambda$1.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6521)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
The code is this:
DocumentReference documentReference = fStore.collection("Users").document(UserID);
documentReference.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {
mName.setText("Name: " + value.getString("Name"));
mPhone.setText("Phone: " + value.getString("Phone"));
mEmail.setText("Email: \n \n" + value.getString("Email"));
mBalance.setText(String.valueOf(value.getDouble("Balance")));
}
});
LogOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fAuth.signOut();
Intent intent = new Intent(getApplicationContext(), Login.class);
startActivity(intent);
}
});
I wanted to know what are the possible reasons why this keeps happening and what should I do?