FireBase身份验证mAuth.createUserWithEmailAndPassword(电子邮件,密码)错误

时间:2019-03-14 22:56:32

标签: android firebase firebase-authentication

因此,我正在尝试向我的应用添加身份验证和登录服务,尽管我无法理解这部分内容,但我仍按照FireBase上告诉的所有步骤进行操作,它表示错误是

  

createUserWithEmailAndPassword(Java.lang.String,Java.lang.String)在   FireBaseAuth无法应用于(Android.widget.text,   Android.widget.text)

在此先感谢您提供的任何帮助。代码如下:

public void Register(View view) {
    Intent intent = new Intent(LoginActivity.this, BottomActivity.class);
    startActivity(intent);
    attemptLogin();

    mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener( this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                Log.d( TAG, "createUserWithEmail:success" );
                FirebaseUser user = mAuth.getCurrentUser();
                updateUI( user );
            } else {
                Log.w(TAG, "createUserWithEmail:failed");
                Toast.makeText(LoginActivity.this, "Authentication failed", Toast.LENGTH_SHORT).show();
                updateUI( null );
            }
        }
    } );
}

电子邮件/密码:

private AutoCompleteTextView email;
private EditText password;

3 个答案:

答案 0 :(得分:1)

这样使用

 mAuth.createUserWithEmailAndPassword(email.getText().toString(), password.getText().toString()).addOnCompleteListener( this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                Log.d( TAG, "createUserWithEmail:success" );
                FirebaseUser user = mAuth.getCurrentUser();
                updateUI( user );
            } else {
                Log.w(TAG, "createUserWithEmail:failed");
                Toast.makeText(LoginActivity.this, "Authentication failed", Toast.LENGTH_SHORT).show();
                updateUI( null );
            }
        }
    } );

答案 1 :(得分:0)

从读取您得到的错误开始,就是说您要传递的参数类型与方法预期的不匹配。它需要String个对象。因此,您需要从TextViewEditText中提取该值。

尝试将email.getText().toString()password.getText().toString而不是emailpassword作为参数传递。

所以

mAuth.createUserWithEmailAndPassword(email.getText().toString(), password.getText().toString())...

答案 2 :(得分:0)

答案很简单,您应该在built.gradle 的依赖项中添加类路径“com.google.gms:google-services:4.3.8” 然后在 built.gradle(app) 中添加 id 'com.google.gms.google-services' 仅此而已。