FORUMS

Runtime error when logging off android stuido mobile app

1 posts
Thanks Meter: 0
 
By Masudh_Deen, Junior Member on 24th June 2020, 03:29 PM
Post Reply Email Thread
I have a java mobile app that is connected with Firebase, login and registration works perfect. I only get an error when I try to logout from the Home Page/Activity. This is the error i get and I don't know what to do.

Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference at com.example.platformapp.HomeActivity.onCreate(Home Activity.java:37)

This is my code for the Home Activity/Page
public class HomeActivity extends AppCompatActivity {
Button btnLogout;
FirebaseAuth myFireBaseAuth;
TextView email;
FirebaseFirestore myfStore;
String userID;
private FirebaseAuth.AuthStateListener myAuthStateListener;

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
email = findViewById(R.id.displayEmail);
myFireBaseAuth = FirebaseAuth.getInstance();
myfStore = FirebaseFirestore.getInstance();

userID = myFireBaseAuth.getCurrentUser().getUid(); // This is line 37


DocumentReference documentReference = myfStore.collection("users").document(userID);
documentReference.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
@override
public void onEvent @nullable DocumentSnapshot documentSnapshot, @nullable FirebaseFirestoreException e) {
email.setText(documentSnapshot.getString("email")) ;
}
});



}
public void logout(View view)
{
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(getApplicationContext(),LoginActivity.class ));
finish();
}
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes