【问题标题】:Firebase doesn't create the account after filling the account creation activity填写帐户创建活动后,Firebase 未创建帐户
【发布时间】:2019-09-07 11:00:52
【问题描述】:

完成帐户创建活动后,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)

【问题讨论】:

  • 你有什么例外吗?
  • @AlexMamo 刚刚在我测试代码时添加了异常结果
  • 您在哪一行代码中遇到了该错误?
  • @AlexMamo 刚刚使用有问题的代码进行了编辑
  • 我完全不明白这是如何工作的。 registerAction 函数不接受任何参数,但是您有一行将两个参数传递给它。那不应该编译。

标签: android firebase firebase-authentication


【解决方案1】:

你写错了案例:

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

解释:

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

我建议在registerAction 中放置 Null 检查用户是否没有输入值。应用程序将崩溃

【讨论】:

  • 好吧,有趣的观察,但我不完全明白这对我的问题有什么帮助
  • @TimmyT 你的问题解决了吗?或者仍然有错误。如果有错误。我会先解决错误然后提供解释。
  • 你能举个例子说明我可以做些什么来解决开关盒问题吗?
  • 要么在函数或方法中提供参数,要么从中删除参数。
猜你喜欢
  • 1970-01-01
  • 2018-04-27
  • 1970-01-01
  • 1970-01-01
  • 2017-03-09
  • 2020-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多