Tomas Mota
Tomas Mota

Reputation: 679

FireBase Authentication mAuth.createUserWithEmailAndPassword(email, password) error

So I'm trying to add an Authentication and Sign in service to my app, I'm following all of the steps told on FireBase although I can't get through this part, it says that the error is

createUserWithEmailAndPassword(Java.lang.String, Java.lang.String) in FireBaseAuth cannot be applied to (Android.widget.text, Android.widget.text)

Thanks in advance for any help given. The code is the following:

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 );
            }
        }
    } );
}

email/password:

private AutoCompleteTextView email;
private EditText password;

Upvotes: 2

Views: 2304

Answers (3)

Talha Chaudhry
Talha Chaudhry

Reputation: 135

The answer is very simple you should add a classpath 'com.google.gms:google-services:4.3.8' in dependencies of built.gradle and then add id 'com.google.gms.google-services' in built.gradle(app) that's all.

Upvotes: 0

Sejpal Pavan
Sejpal Pavan

Reputation: 140

use like this

 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 );
            }
        }
    } );

Upvotes: 1

ribbit
ribbit

Reputation: 1283

From reading the error you're getting, it's saying that the type of the parameters you're passing are not matching what the method expects. It expects String objects. So you'd need to extract that value from your TextView and EditText.

Try passing email.getText().toString() and password.getText().toString as parameters instead of email and password.

So

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

Upvotes: 0

Related Questions