FirebaseAuth.getCurrentUser()
is returning null
value. Previously my code worked fine but since couple of days its returning currentUser
as null
.
Also I've tried my app on another device and in that device everything is working fine with the same code.
mAuth=FirebaseAuth.getInstance();
mCurrentUser=mAuth.getCurrentUser()
mUserDatabase=FirebaseDatabase.getInstance().getReference().child("Users")
.child(mCurrentUser.getUid());
Exception:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
I have already tried erasing app data and uninstalling and reinstalling my app on my device but nothing worked.
Is there a problem with my device or Firebase
?
It looks like the user isn't signed into your app, which causes mCurrentUser.getUid()
to throw an exception.
The solution is to only call getUid()
is there is a signed-in yser:
mCurrentUser=mAuth.getCurrentUser();
if (mCurrentUser != null) {
mUserDatabase=FirebaseDatabase.getInstance().getReference().child("Users")
.child(mCurrentUser.getUid());
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments