gpt4 book ai didi

java - 尝试在空对象引用上调用虚拟方法 'boolean java.lang.String.equals(java.lang.Object)'

转载 作者:行者123 更新时间:2023-12-01 17:52:18 25 4
gpt4 key购买 nike

 This is the errror, tried a few things but still to no avail.

java.lang.NullPointerException:尝试在 com.dllibrary.cart 的空对象引用上调用虚拟方法“boolean java.lang.String.equals(java.lang.Object)” .SigninMainActivity$1$1.onDataChange(SigninMainActivity.java:56) 在 com.google.android.gms.internal.zzegf.zza(来源未知) 在 com.google.android.gms.internal.zzeia.zzbyc(来源未知) 在 com.google.android.gms.internal.zzeig.run(来源未知) 在 android.os.Handler.handleCallback(Handler.java:815) 在 android.os.Handler.dispatchMessage(Handler.java:104) 在 android.os.Looper.loop(Looper.java:194) 在 android.app.ActivityThread.main(ActivityThread.java:5637) 在 java.lang.reflect.Method.invoke( native 方法) 在 java.lang.reflect.Method.invoke(Method.java:372) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

我的登录方法的代码

     signin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

final ProgressDialog mdialog = new ProgressDialog(SigninMainActivity.this);
mdialog.setMessage("Please waiting");
mdialog.show();
table_user.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//check if user not exist
if (dataSnapshot.child(phone.getText().toString()).exists()) {
//Get User Information
mdialog.dismiss();

User user = dataSnapshot.child(phone.getText().toString()).getValue(User.class);
if (user.getPassword().equals(password.getText().toString())) {
Intent homeIntent= new Intent(SigninMainActivity.this, home.class);
Common.currentUser = user;
startActivity(homeIntent);
finish();
} else {

Toast.makeText(SigninMainActivity.this, "Sign in failed", Toast.LENGTH_SHORT).show();


}
}else{
mdialog.dismiss();
Toast.makeText(SigninMainActivity.this, "User Does Not exist", Toast.LENGTH_SHORT).show();
}
}

第 56 行位于“if(user.getPassword.equals)”

最佳答案

检查我实现的以下代码是否有我预期的更改。

    signin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

final ProgressDialog mdialog = new ProgressDialog(SigninMainActivity.this);
mdialog.setMessage("Please waiting");
mdialog.show();
table_user.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//check if user not exist
if (dataSnapshot.child(phone.getText().toString()).exists()) {
//Get User Information
mdialog.dismiss();

User user = dataSnapshot.child(phone.getText().toString()).getValue(User.class);
//Check the null
if (user.getPassword() != null && password.getText() != null && user.getPassword().equals(password.getText().toString())) {
Intent homeIntent= new Intent(SigninMainActivity.this, home.class);
Common.currentUser = user;
startActivity(homeIntent);
finish();
} else {

Toast.makeText(SigninMainActivity.this, "Sign in failed", Toast.LENGTH_SHORT).show();


}
}else{
mdialog.dismiss();
Toast.makeText(SigninMainActivity.this, "User Does Not exist", Toast.LENGTH_SHORT).show();
}
}

关于java - 尝试在空对象引用上调用虚拟方法 'boolean java.lang.String.equals(java.lang.Object)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48679650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com