-1

I'm begginer in coding and I don't know how to solve this bug. I'm creating an app and in the login class the app stop working when fields are wmpty and pressing login button. Please help me with this

This is the code:

    binding.submitBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String email, pass;
            email = binding.emailBox.getText().toString();
            pass = binding.passwordBox.getText().toString();

            dialog.show();

            auth.signInWithEmailAndPassword(email, pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    dialog.dismiss();
                    if(task.isSuccessful()){
                        startActivity(new Intent(LoginActivity.this, MainActivity.class));
                        finish();

                    } else {
                        Toast.makeText(LoginActivity.this, task.getException().getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
            });

        }
    });

1 Answers1

0

You should make operation to check if field empty or not

if (binding.emailBox.getText().toString().isEmpty() || binding.passwordBox.getText().toString().isEmpty()) {
    // Do something, erro dialog or whatever
} else {
    login();
}

Try to check logcat and read the message

Sasmita
  • 137
  • 1
  • 12