傻瓜! 我在调试方面经验不足,但是正在努力解决此问题。 对你们来说可能很明显,但是如果有人可以帮助我,那就很好
这是错误:
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)
这是我的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();
}
问题是,通过单击我的“登录”按钮,错误弹出。 不知道发生了什么。另一个按钮“注册”可以正常工作,将数据丢入Firebase中,但“登录”对话框甚至没有打开。
如果您可以就更改或修复方法给我直接的答案,那对我真的很有帮助。 问候 Mitkashin-
答案 0 :(得分:1)
您需要在点击时将登录代码移到肯定按钮中。//登录
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);
}
});
}
});
答案 1 :(得分:1)
您将登录代码放在错误的位置。您需要将其放入“登录”按钮点击监听器中,如下所示:
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);
}
});
}
});
答案 2 :(得分:1)
正如其他人所说,您对auth.signInWithEmailAndPassword()
的呼叫在错误的位置。您是在构建AlertDialog
的方法中调用它的,因此它在您按下按钮后立即运行,而不是在按下“登录”按钮时运行。该对话框未显示,因为您的应用在构建对话框之前就崩溃了。
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)
来自堆栈跟踪的前几行非常清楚地说明了signInWithEmailAndPassword()
被赋予了错误的参数。从您的问题中我可以看出,您似乎很急于解决此问题,但请花些时间阅读和理解这些痕迹。他们通常非常有帮助