这段代码昨天还在运行,今天又试图运行,突然出现了这个错误。
我可以在我的firebase用户数据库中看到,我试图创建的邮件用户正在被创建。如我的日志所述(从firebase预定义):“电子邮件地址已被另一个帐户使用”。我不明白的是,为什么我得到一个空指针,它找不到用户,因此不发送验证电子邮件。它怎么可能是空的,而且还说已经有一个帐户与该电子邮件?
相关代码:
//Method for signing up a new user
public void signUp(String email, String pwd, Context context, Activity activity){
//Listener which gives response when the createUser method has run
mContext = context;
mActivity = activity;
auth.createUserWithEmailAndPassword(email, pwd)
.addOnCompleteListener(mActivity, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.i(TAG, "createUserWithEmail:success");
FirebaseUser user = auth.getCurrentUser();
if (user != null) {
user.sendEmailVerification()
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.i(TAG, "Verification Email sent.");
CreateNewUserActivity cna = new CreateNewUserActivity();
cna.visibel();
}
}
});
}
} else {
Toast.makeText(mContext, "Sign-up failed.", Toast.LENGTH_SHORT).show();
Log.i(TAG, "onComplete: " + task.getException());
}
}
});
}
更相关的代码:
public void setupAuthStateListener(final MainActivity activity) {
auth.addIdTokenListener(new FirebaseAuth.IdTokenListener() {
@Override
public void onIdTokenChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() != null){
if (firebaseAuth.getCurrentUser().isEmailVerified()){
auth.removeIdTokenListener(this);
firebaseHandler.loadDB();
Log.i(TAG, "Signed in from firebase");
Intent intent = new Intent(activity, MenuActivity.class);
activity.finish();
activity.startActivity(intent);
}else{
auth.signOut();
Toast.makeText(activity, "Your email is not verified. Verify the email to log in.", Toast.LENGTH_LONG).show();
Log.i(TAG, "onIdTokenChanged: Email not verified");
}
}else {
Log.i(TAG, "Signed out of firebase");
}
}
});
}
日志:
2021-01-07 09:53:25.004 4117-4117/studios.kundby.fitnessapp I/AuthManager: onIdTokenChanged: Email not verified
2021-01-07 09:53:25.007 4117-4117/studios.kundby.fitnessapp I/AuthManager: onComplete: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.internal.firebase-auth-api.zzwg com.google.firebase.auth.FirebaseUser.zze()' on a null object reference
2021-01-07 09:53:25.007 4117-4117/studios.kundby.fitnessapp I/AuthManager: Signed out of firebase
2021-01-07 09:53:25.077 4117-4330/studios.kundby.fitnessapp I/chatty: uid=10080(studios.kundby.fitnessapp) RenderThread identical 1 line
2021-01-07 09:53:34.811 4117-4169/studios.kundby.fitnessapp W/System: Ignoring header X-Firebase-Locale because its value was null.
2021-01-07 09:53:35.000 4117-4117/studios.kundby.fitnessapp I/AuthManager: onComplete: com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account.
2021-01-07 09:53:36.497 4117-4169/studios.kundby.fitnessapp W/System: Ignoring header X-Firebase-Locale because its value was null.
1条答案
按热度按时间ulmd4ohb1#
这个问题是因为我注销太快。