填写帐户创建活动后,Firebase不会创建帐户

时间:2019-09-07 11:00:52

标签: android firebase firebase-authentication

完成帐户创建活动后,firebase不会创建该帐户,并显示尚未创建新用户。我查看了Firebase网站上的文档,但似乎无法理解我所缺少的内容。 下面是负责帐户创建的功能。

我还检查了android studio是否具有所有firebase SDK的最新版本,以及我是否已使用firebase助手正确配置了项目。

在我的onClick函数中,也会因为我的异常错误而受到影响。 我在我的registerAction()和onClick()函数中都强调了有问题的行。

    public void onClick(View v) {
    switch (v.getId()) {
        case R.id.registerButton:
        registerAction(EmailField.getText().toString(), PasswordField.getText().toString()); **Error handles here**
        break;

        case R.id.loginButton:
            loginAction(EmailField.getText().toString(), PasswordField.getText().toString());
            break;

        case R.id.resendConfirmationButton:
            confirmAction();
            break;

        case R.id.resetButton:
            resetAction();
            break;

        case R.id.forgotButton:
            forgotPasswordAction(EmailField.getText().toString());
            break;

        case R.id.showLoginButton:
            showLoginAction(true);
            break;

        case R.id.showRegisterButton:
            showRegisterAction(true);
            break;
    }

}
 private void registerAction() {
      String email = EmailField.getText().toString();
      String password = PasswordField.getText().toString();

// This sends the users email and password to firebase to save as a token.
    Log.d(TAG, "Create user account: " + email);
    mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { **Error also occurs here**
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        if(task.isSuccessful()) {
            // This is called when the user registration as expected.
            Log.d(TAG, "CreatedUserWithEmail:success");
            Toast.makeText(AuthenticationActivity.this, "Registration was successful", Toast.LENGTH_LONG).show();
            mAuth.getCurrentUser();
        } else {
            // In the event that user authentication fails.
            Log.w(TAG, "CreatedWithEmail:failure", task.getException());
            Toast.makeText(AuthenticationActivity.this, "User registration has failed", Toast.LENGTH_LONG).show();
        }
    }
});

运行代码后,Android Studio会返回此异常:

   Process: com.lyfeforcelabs.nitelyfe, PID: 6103
java.lang.IllegalArgumentException: Given String is empty or null
    at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(Unknown Source:5)
    at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(Unknown Source:247)
    at com.lyfeforcelabs.nitelyfe.AuthenticationActivity.registerAction(AuthenticationActivity.java:143)
    at com.lyfeforcelabs.nitelyfe.AuthenticationActivity.onClick(AuthenticationActivity.java:82)
    at android.view.View.performClick(View.java:6597)
    at android.view.View.performClickInternal(View.java:6574)
    at android.view.View.access$3100(View.java:778)
    at android.view.View$PerformClick.run(View.java:25885)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

1 个答案:

答案 0 :(得分:3)

您写错了Case:

case R.id.registerButton:
        registerAction();
        break;

说明:

您的Switch案例包含registerAction方法/函数,不带任何参数。

我建议在registerAction中输入Null,以检查用户是否未输入值。应用程序将崩溃

相关问题