пока я тестирую свое приложение, я получаю следующую ошибку в Android -Studio-logcat:
прежде, чем получить эту ошибку, я был нажат на setPositiveButton
кнопки диалогового окна предупреждения, имя - "EMAIL ME" с пустым EditText.
и затем я получил К сожалению, твист прекратился.
пожалуйста, мне нужна помощь !!
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.testing.twist, PID: 30072
java.lang.IllegalArgumentException: Given String is empty or null
at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(Unknown
Source)
at com.google.firebase.auth.FirebaseAuth.sendPasswordResetEmail(com.google.firebase:firebase-auth@@19.3.1:307)
at com.testing.twist.login.beginforgotpasswd(login.java:141)
at com.testing.twist.login.access$400(login.java:26)
at com.testing.twist.login$4.onClick(login.java:119)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
вот какой-то код моего логина. java файл
public class login extends AppCompatActivity {
private EditText Email;
private EditText password;
private Button btn_login;
private TextView tv_signup;
private FirebaseAuth firebaseAuth;
private TextView tv_forgotpasswd_l;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Email = (EditText)findViewById(R.id.et_email_l);
password = (EditText)findViewById(R.id.et_passwd_l);
btn_login = (Button)findViewById(R.id.btn_l);
tv_signup = (TextView)findViewById(R.id.tv_sign_up);
tv_forgotpasswd_l = (TextView)findViewById(R.id.tv_f_passwd);
firebaseAuth = FirebaseAuth.getInstance();
FirebaseUser user = firebaseAuth.getCurrentUser();
if(user != null){
finish();
startActivity(new Intent(login.this, MainActivity.class));
}
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
validate(Email.getText().toString(), password.getText().toString());
}
});
tv_signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(login.this,Register.class));
}
});
// Login button hide
Email.addTextChangedListener(loginTextWatcher);
password.addTextChangedListener(loginTextWatcher);
// recover pass textview click
tv_forgotpasswd_l.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showForgotpasswdDialog();
}
});
}
// Alert Dialog
private void showForgotpasswdDialog()
{
//Dialog Box code
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Forgot your password?");
//set linear layout
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(30,30,30,30);
Email.setPadding(10,10,10,10);
//view to set an dialog
final EditText Email = new EditText(this);
Email.setHint("Email");
Email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
//text view
linearLayout.addView(Email);
builder.setView(linearLayout);
//text style
// Text view
final TextView tv = new TextView(this);
tv.setTextSize(14);
tv.setTypeface(null, Typeface.BOLD);
tv.setTextColor(Color.parseColor("black"));
tv.setText("Unfortunately, if you have never given us your email, we will not be able to reset your password.");
tv.setPadding(10,10,10,10);
linearLayout.addView(tv);
builder.setView(linearLayout);
//buttons for EMAIL ME
builder.setPositiveButton("EMAIL ME", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//input email
String email = Email.getText().toString().trim();
beginforgotpasswd(email);
}
});
//buttons for CANCEL
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
// dismiss dialog
dialog.dismiss();
}
});
///show dialog
builder.create().show();
}
private void beginforgotpasswd(String email)
{
firebaseAuth.sendPasswordResetEmail(email).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task)
{
if (task.isSuccessful())
{
Toast.makeText(login.this,"Email sent",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(login.this,"Failed...",Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
//get and show proper error message
Toast.makeText(login.this,""+e.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}
private TextWatcher loginTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String emailInput = Email.getText().toString().trim();
String passwdInput = password.getText().toString().trim();
btn_login.setEnabled(!emailInput.isEmpty() && !passwdInput.isEmpty());
}
@Override
public void afterTextChanged(Editable editable) {
}
};
private void validate(String usremail, String usrpassword){
firebaseAuth.signInWithEmailAndPassword(usremail,usrpassword).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(Task<AuthResult> task) {
if(task.isSuccessful()){
//Toast.makeText(login.this, "Login Successful",Toast.LENGTH_SHORT).show();
checkEmailVerification();
}
else{
Toast.makeText(login.this, "Login Failed",Toast.LENGTH_SHORT).show();
}
}
});
}
private void checkEmailVerification()
{
FirebaseUser firebaseUser = firebaseAuth.getInstance().getCurrentUser();
Boolean emailflag = firebaseUser.isEmailVerified();
if(emailflag)
{
finish();
startActivity(new Intent(login.this,MainActivity.class));
}
else
{
Toast.makeText(login.this, "Verify your email", Toast.LENGTH_SHORT).show();
firebaseAuth.signOut();
}
}
}