简体   繁体   English

给定的String为空或null

[英]Given String is empty or null

quickie!! 匆匆!! I'm not much experienced with debugging but I'm struggling to fix this. 我在调试方面经验不足,但是正在努力解决此问题。 It might be obvious for you guys but if someone can help me it would be good 对你们来说可能很明显,但是如果有人可以帮助我,那将是很好

This is the error : 这是错误:

2019-03-12 04:12:59.163 17226-17226/com.app.mk.transport E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.app.mk.transport, PID: 17226
    java.lang.IllegalArgumentException: Given String is empty or null
        at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(Unknown Source:11)
        at com.google.firebase.auth.FirebaseAuth.signInWithEmailAndPassword(Unknown Source:0)
        at com.app.mk.transport.MainActivity.showLogInDialog(MainActivity.java:119)
        at com.app.mk.transport.MainActivity.access$100(MainActivity.java:29)
        at com.app.mk.transport.MainActivity$2.onClick(MainActivity.java:65)
        at android.view.View.performClick(View.java:6897)
        at android.widget.TextView.performClick(TextView.java:12693)
        at android.view.View$PerformClick.run(View.java:26101)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6944)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
2019-03-12 04:12:59.214 17226-17233/com.app.mk.transport I/zygote64: Do partial code cache collection, code=55KB, data=47KB
2019-03-12 04:12:59.215 17226-17233/com.app.mk.transport I/zygote64: After code cache collection, code=55KB, data=47KB
2019-03-12 04:12:59.215 17226-17233/com.app.mk.transport I/zygote64: Increasing code cache capacity to 256KB
2019-03-12 04:12:59.216 17226-17233/com.app.mk.transport I/zygote64: Compiler allocated 9MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)

This is my MainActivity class: 这是我的MainActivity类:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Firebase Init
        auth = FirebaseAuth.getInstance();
        db = FirebaseDatabase.getInstance();
        users = db.getReference("Users");

        // Init View
        btnRegister = (Button) findViewById(R.id.btnRegister);
        btnSignIn = (Button) findViewById(R.id.btnSignIn);
        rootLayout = (RelativeLayout) findViewById(R.id.rootLayout);

        //Event
        btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showRegisterDialog();
            }
        });

        btnSignIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showLogInDialog();
            }
        });

    }

    private void showLogInDialog() {
        final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle("SIGN IN ");
        dialog.setMessage("Please use email to sign in!");

        LayoutInflater inflater = LayoutInflater.from(this);

        View layout_login = inflater.inflate(R.layout.layout_login, null);

        final MaterialEditText edtEmail = layout_login.findViewById(R.id.edtEmail);
        final MaterialEditText edtPassword = layout_login.findViewById(R.id.edtPassword);

        dialog.setView(layout_login);

        //set button
        dialog.setPositiveButton("SIGN IN", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.dismiss();

                btnSignIn.setEnabled(false);

                //Check validation

                if (TextUtils.isEmpty(edtEmail.getText().toString())) {
                    Snackbar.make(rootLayout, "Please enter email address!", Snackbar.LENGTH_SHORT).show();
                    return;
                }

                if (TextUtils.isEmpty(edtPassword.getText().toString())) {
                    Snackbar.make(rootLayout, "Please enter your Password!", Snackbar.LENGTH_SHORT).show();
                    return;
                }

                if (edtPassword.getText().toString().length() < 6) {
                    Snackbar.make(rootLayout, "Password is too short!", Snackbar.LENGTH_SHORT).show();
                    return;
                }
            }

        });


        final SpotsDialog waitingDialog = new SpotsDialog(MainActivity.this, "Loading...", R.style.Orange);

        waitingDialog.show();

        //Login
        auth.signInWithEmailAndPassword(edtEmail.getText().toString(), edtPassword.getText().toString())
                .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                    @Override
                    public void onSuccess(AuthResult authResult) {
                        waitingDialog.dismiss();
                        startActivity(new Intent(MainActivity.this, Welcome.class));
                        finish();
                    }
                }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                waitingDialog.dismiss();

                Snackbar.make(rootLayout, "Failed " + e.getMessage(), Snackbar.LENGTH_SHORT).show();

                btnSignIn.setEnabled(true);
            }
        });

        dialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.dismiss();

            }
        });


        dialog.show();
    }

The problem is, by clicking my "Log in" button the error pops up. 问题是,通过单击我的“登录”按钮,错误弹出。 Not sure what's going on. 不知道发生了什么。 The other button "Register" works just fine, throws data in the firebase but the Sign IN dialog is not even opening. 另一个按钮“注册”可以很好地工作,将数据丢入Firebase中,但“登录”对话框甚至没有打开。

If you can give me straight answer on what to change or how to fix it, it will be really helpful for me. 如果您可以就更改或修复方法给我直接的答案,那对我真的很有帮助。 Greetings Mitkashin- 问候Mitkashin-

You need to move your sign in code into your positive button on click.//Login 您需要在单击时将登录代码移到肯定按钮中。//登录

 dialog.setPositiveButton("SIGN IN", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.dismiss();

                btnSignIn.setEnabled(false);

                //Check validation

                if (TextUtils.isEmpty(edtEmail.getText().toString())) {
                    Snackbar.make(rootLayout, "Please enter email address!", Snackbar.LENGTH_SHORT).show();
                    return;
                }

                if (TextUtils.isEmpty(edtPassword.getText().toString())) {
                    Snackbar.make(rootLayout, "Please enter your Password!", Snackbar.LENGTH_SHORT).show();
                    return;
                }

                if (edtPassword.getText().toString().length() < 6) {
                    Snackbar.make(rootLayout, "Password is too short!", Snackbar.LENGTH_SHORT).show();
                    return;
                }

                auth.signInWithEmailAndPassword(edtEmail.getText().toString(), edtPassword.getText().toString())
                .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                    @Override
                    public void onSuccess(AuthResult authResult) {
                        waitingDialog.dismiss();
                        startActivity(new Intent(MainActivity.this, Welcome.class));
                        finish();
                    }
                }).addOnFailureListener(new OnFailureListener() {
                   @Override
                   public void onFailure(@NonNull Exception e) {
                      waitingDialog.dismiss();

                      Snackbar.make(rootLayout, "Failed " + e.getMessage(), Snackbar.LENGTH_SHORT).show();

                      btnSignIn.setEnabled(true);
                  }
               });


            }

        });

You are putting signin code in the wrong place. 您将登录代码放在错误的位置。 You need to put it inside your Signin button click listener like this: 您需要将其放入“登录”按钮点击监听器中,如下所示:

dialog.setPositiveButton("SIGN IN", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        dialogInterface.dismiss();

        btnSignIn.setEnabled(false);

        //Check validation

        if (TextUtils.isEmpty(edtEmail.getText().toString())) {
            Snackbar.make(rootLayout, "Please enter email address!", Snackbar.LENGTH_SHORT).show();
            return;
        }

        if (TextUtils.isEmpty(edtPassword.getText().toString())) {
            Snackbar.make(rootLayout, "Please enter your Password!", Snackbar.LENGTH_SHORT).show();
            return;
        }

        if (edtPassword.getText().toString().length() < 6) {
            Snackbar.make(rootLayout, "Password is too short!", Snackbar.LENGTH_SHORT).show();
            return;
        }

        //Login
        auth.signInWithEmailAndPassword(edtEmail.getText().toString(), edtPassword.getText().toString())
            .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult authResult) {
                    waitingDialog.dismiss();
                    startActivity(new Intent(MainActivity.this, Welcome.class));
                    finish();
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    waitingDialog.dismiss();

                    Snackbar.make(rootLayout, "Failed " + e.getMessage(), Snackbar.LENGTH_SHORT).show();

                    btnSignIn.setEnabled(true);
                }
        });
    }

});

As others have said, your call to auth.signInWithEmailAndPassword() is in the wrong place. 正如其他人所说,您对auth.signInWithEmailAndPassword()调用在错误的位置。 You're calling it in the method that builds your AlertDialog , so it's run as soon as you press the button instead of running when the Sign In button is pressed. 您是在构建AlertDialog的方法中调用它的,因此它在您按下按钮后立即运行,而不是在按下Sign In按钮时运行。 The dialog doesn't show because your app crashes before it's done building the dialog box. 该对话框未显示,因为您的应用程序在构建对话框之前就崩溃了。

    java.lang.IllegalArgumentException: Given String is empty or null
    at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(Unknown Source:11)
    at com.google.firebase.auth.FirebaseAuth.signInWithEmailAndPassword(Unknown Source:0)

These first few lines from the stack trace explain very clearly that signInWithEmailAndPassword() is being given bad arguments. 堆栈跟踪的前几行非常清楚地说明了signInWithEmailAndPassword()被赋予了错误的参数。 I can see from your question that you seem to be in a real hurry to fix this, but please take the time to read and understand the traces. 从您的问题中我可以看出,您似乎很急于解决此问题,但请花些时间阅读和理解这些痕迹。 They're usually very helpful 他们通常非常有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM