Issue
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();
}
}
});
}
});
}
}`
Solution
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.
Answered By - Sergey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.