首页 > 解决方案 > Firebase 身份验证不会创建帐户

问题描述

我不知道我的代码或 firebase 控制台出了什么问题,但是当我运行应用程序并单击提交按钮尝试创建一个帐户时,它会运行.addOnFailureListener,但我不知道为什么。

很抱歉描述模糊,但如果有人能告诉我我是否做错了什么,我将非常感激。

FirebaseFirestore db = FirebaseFirestore.getInstance();
private FirebaseAuth mAuth = FirebaseAuth.getInstance();
private TextView mTextMessage;
private StorageReference mStorageRef;

@Override
@TargetApi(24)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_account_page);

                //creating user if all previous data validation checks out
                if (nextPage == true) {mAuth.createUserWithEmailAndPassword(userInputArrayList.get(1), userInputArrayList.get(2)).addOnCompleteListener(CreateAccountPage.this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                Log.d(TAG,"9");
                                // Sign in success, update UI with the signed-in user's information
                                Log.d(TAG,"Sign up Successful");
                                FirebaseUser user = mAuth.getCurrentUser();
                                updateUI(user, userInputArrayList, tglBtnAdmin);
                            } else {
                                // If sign in fails, display a message to the user.
                                showToast("Could not create an account, please try again later.");
                            }
                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            showToast("Account could not be created, please try again later");
                        }
                    });
                }
            } else {
                showToast("Please fill all fields.");
            }
        }
    });
}

}

错误信息

com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The email address is badly formatted.
at com.google.firebase.auth.api.internal.zzdr.zzb(Unknown Source:30)
at com.google.firebase.auth.api.internal.zzeu.zza(Unknown Source:16)
at com.google.firebase.auth.api.internal.zzen.zzc(Unknown Source:33)
at com.google.firebase.auth.api.internal.zzep.onFailure(Unknown Source:49)
at com.google.firebase.auth.api.internal.zzdx.dispatchTransaction(Unknown Source:18)
at com.google.android.gms.internal.firebase_auth.zza.onTransact(Unknown Source:13)
at android.os.Binder.execTransact(Binder.java:697)

标签: androidfirebasefirebase-authentication

解决方案


尝试在 onCreate 方法中获取类的实例,然后尝试。如果这不起作用,请发布正确的错误堆栈跟踪。通过这个,我们无法确定错误发生的位置和原因。

堆栈跟踪显示电子邮件格式错误。这意味着,您输入的电子邮件地址无效或格式不正确。确保输入正确的地址。尝试检查您的原始电子邮件地址并调试并检查它所取的值输入。随意发表评论。

在 userInputArrayList 中,您将收到电子邮件和密码。我假设您在该 arraylist 中存储的只有两个字段。arrayList 以编程方式从“0”开始。所以,尝试输入 get(0) 用于电子邮件,get(1) 用于密码。希望这会有所帮助


推荐阅读