I have created an android chat app using firebase - the app works fine but when first opened, the app crashes in login page but after this the app restarts and works fine. Please help me with a solution because I am a beginner in this field tell me what I should change to make it work
My logcat: beginning of crash
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference at com.dndna.chat_rooms.views.base.BasePresenter.getCurrentUserId(BasePresenter.java:78) at com.dndna.chat_rooms.views.main.MainPresenter.checkPendingNotification(MainPresenter.java:198) at com.dndna.chat_rooms.views.main.MainActivity.onResume(MainActivity.java:262) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1456) at android.app.Activity.performResume(Activity.java:7614) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4412)
The problem seems to be in these locations
public void checkPendingNotification() {
if (getCurrentUserId() != null)
notifyManager.checkPendingNotification(this::showBadgeAt);
}
and
if (presenter != null) {
presenter.checkPendingNotification();
}
and
protected String getCurrentUserId() {
FirebaseAuth.getInstance();
return FirebaseAuth.getInstance().getCurrentUser().getUid();
}