0

I have an android app and a Firebase database. The login I've set is with email and password. It works great, but when I try and login with blank email and password the app crashes.

Here is my code

final String Email = email.getText().toString();
final String Password = password.getText().toString();
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(ThisActivity.this, new OnCompleteListener<AuthResult>() {
          @Override
          public void onComplete(@NonNull Task<AuthResult> task) {
                      if (!task.isSuccessful()) {
                                Toast.makeText(ThisActivity.this, "sign in error", Toast.LENGTH_SHORT).show();
                      } else
                                mAuth.addAuthStateListener(firebaseAuthListener);
          }
});
break;
nhoxbypass
  • 9,695
  • 11
  • 48
  • 71
osoda
  • 41
  • 2
  • 6

2 Answers2

1

This would help you :)

final String Email = email.getText().toString();
final String Password = password.getText().toString();

if(!TextUtils.isEmpty(Email) && !TextUtils.isEmpty(Password)) {
        mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(CustomerLoginActivty.this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (!task.isSuccessful()) {

                        Toast.makeText(ThisActivity.this, "sign in error", Toast.LENGTH_SHORT).show();
                    } else
                        mAuth.addAuthStateListener(firebaseAuthListener);
                }
            });
            break;
        }
Abir Hossain
  • 111
  • 7
0

Both parameters email and password should not be either null or empty. So if you need to log with blank spaces, make sure you validate the fields and not send a null or an empty to the method signInWithEmailAndPassword

camilocons
  • 31
  • 2