Firebase Android重置密码错误

时间:2017-04-16 20:58:29

标签: android xml firebase firebase-authentication

以下是用户界面的截图:

Screenshot

我不知道代码有什么问题。我只是想向用户的电子邮件发送重置密码电子邮件。如果您愿意,可以查看完整代码here。非常感谢任何帮助,提前感谢! :d

代码:

    public void PassResetViaEmail(View view)
{
    AlertDialog.Builder alertdialog = new AlertDialog.Builder(Settings.this);
    alertdialog.setTitle("Reset password");
    alertdialog.setMessage("Enter email below");

    input = new EditText(this);
    email = input.getText().toString().trim();
    alertdialog.setView(input);


    alertdialog.setPositiveButton("Send", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ResetEmailSender();
        }
    });
    alertdialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alertdialog.show();
}

public void ResetEmailSender()
{
    auth = FirebaseAuth.getInstance();
    auth.sendPasswordResetEmail(email)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Toast.makeText(Settings.this, "We have sent you instructions to reset your password!", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(Settings.this, "Failed to send reset email!", Toast.LENGTH_SHORT).show();
                    }
                }
            });
}

错误:

                                                                  java.lang.IllegalArgumentException: Given String is empty or null
                                                                      at com.google.android.gms.common.internal.zzac.zzdr(Unknown Source)
                                                                      at com.google.firebase.auth.FirebaseAuth.sendPasswordResetEmail(Unknown Source)
                                                                      at com.safariagaming.flix.Settings.ResetEmailSender(Settings.java:107)
                                                                      at com.safariagaming.flix.Settings$2.onClick(Settings.java:92)
                                                                      at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:161)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                      at android.os.Looper.loop(Looper.java:154)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

1 个答案:

答案 0 :(得分:2)

  

因为我输入了一封电子邮件,所以这是不可能的

也许你做过,但是因为你得到了这个非常奇怪的代码,这没什么区别:

input = new EditText(this);
email = input.getText().toString().trim();

创建EditText并立即从中读取是没有意义的。因为它还没有显示,所以每次都不会给你任何空字符串。一旦取消对话框,你应该考虑阅读它。