ahmadtam
ahmadtam

Reputation: 29

specific button close the app when clicked

the app keeps closed when i clicked sign in button i think the error is from the code but i dont know where is the error exactly

any help!

just this button kick me from he app, other buttons works good!

public class login extends AppCompatActivity {


    EditText username;
    EditText password;
    Button userlogin;
    FirebaseAuth firebseAuth;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);


        username = findViewById(R.id.login_username);
        password = findViewById(R.id.login_password);
        userlogin = findViewById(R.id.login_btn);

        firebseAuth = FirebaseAuth.getInstance();
        userlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                firebseAuth.signInWithEmailAndPassword(username.getText().toString(),password.getText().toString())
                        .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                            @Override
                            public void onComplete(@NonNull Task<AuthResult> task) {
                                if(task.isSuccessful()){
                                    startActivity(new Intent(login.this,profile.class));
                                }else{
                                    Toast.makeText(login.this,"hellow", Toast.LENGTH_LONG).show();
                                }

                            }
                        });
            }
        });

    }
}`

Upvotes: 0

Views: 44

Answers (1)

Sergio
Sergio

Reputation: 30645

You can check if username and password strings are not empty, then make request:

String passwordStr = password.getText().toString() 
String usernameStr = username.getText().toString() 
if (!TextUtils.isEmpty(passwordStr) && !TextUtils.isEmpty(usernameStr) {
    firebseAuth.signInWithEmailAndPassword(usernameStr, passwordStr).addOnCompleteListener(....)
}

It seems firebseAuth.signInWithEmailAndPassword() throws an exception if strings are empty.

Upvotes: 1

Related Questions