0

My app was working perfectly before until this morning when I ran my code in android studio and it crashed, I checked logcat and it pointed to these two places

first is in the MainActivity.java in the onStart

  mAuth = FirebaseAuth.getInstance();


    mToolbar = findViewById(R.id.main_app_bar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setTitle("ChatPlus");


    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

    loadFragment(new RequestFragment());


    if (mAuth.getCurrentUser() != null) {
        mUserRef = FirebaseDatabase.getInstance().getReference().child("Users").child(mAuth.getCurrentUser().getUid());

    }
}


@Override
public void onStart() {
    super.onStart(); //crashes here
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();

    if (currentUser == null) {
        sendtostart();
    } else {
        mUserRef.child("online").setValue("true");
    }
}

@Override
protected void onStop() {
    super.onStop();

    FirebaseUser currentUser = mAuth.getCurrentUser();

    if (currentUser != null) {
        mUserRef.child("online").setValue(ServerValue.TIMESTAMP);
    }
}

second place is in my RequestFragment

 mMainView = inflater.inflate(R.layout.fragment_request, container, false);

    mRequestList = (RecyclerView) mMainView.findViewById(R.id.request_list);
    mAuth = FirebaseAuth.getInstance();

    mCurrent_user_id = mAuth.getCurrentUser().getUid(); //at this line


    mRequestDatabase = FirebaseDatabase.getInstance().getReference().child("Friend_req").child(mCurrent_user_id);
    mRequestDatabase.keepSynced(true);
    mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
    mUsersDatabase.keepSynced(true);
KENdi
  • 7,576
  • 2
  • 16
  • 31
Mani
  • 423
  • 1
  • 4
  • 13
  • Check [this answer](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Tamir Abutbul Dec 20 '18 at 10:47
  • 1
    if `mAuth.getCurrentUser()` returns null it means that you are not longer signed-in. As @TamirAbutbul pointed out you must be careful with null pointer exception and always check them. Moreover you must pay attention and always check if your current user is singed in or not. – shadowsheep Dec 20 '18 at 10:47

0 Answers0