Mon profileActivity ne démarre pas en raison de faire une exception NullPointer, je suppose que le problème est avecImpossible d'obtenir email de l'utilisateur, en raison de ce que je reçois NullPointer
FirebaseUser user = firebaseAuth.getCurrentUser();
textViewUserEmail.setText("Welcome " + user.getEmail());`
et que le courrier électronique est nul mais je ne peux pas comprendre pourquoi. Voici mon code:
import com.google.firebase.auth.FirebaseAuth;
intérieur onCreate
:
textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail);
firebaseAuth = FirebaseAuth.getInstance();
if (firebaseAuth.getCurrentUser() == null) {
finish();
startActivity(new Intent(this, Home.class));
}
FirebaseUser user = firebaseAuth.getCurrentUser();
textViewUserEmail.setText("Welcome " + user.getEmail());
Voici l'erreur du journal:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liamthedeveloper.foodiez/com.liamthedeveloper.foodiez.ProfileActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getEmail()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getEmail()' on a null object reference
at com.liamthedeveloper.foodiez.ProfileActivity.onCreate(ProfileActivity.java:66)
at android.app.Activity.performCreate(Activity.java:6942)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
quelle est votre 66e ligne de l'activité? – Sahil
'Causé par: java.lang.NullPointerException: Tentative d'invocation de la méthode virtuelle 'java.lang.String com.google.firebase.auth.FirebaseUser.getEmail()' sur une référence d'objet nul' -> C'est le problème. Il semble que 'user' est' null'. –
@Sahil ma 66e ligne est textViewUserEmail.setText ("Bienvenue" + user.getEmail()); – liam