gpt4 book ai didi

java - 空指针异常

转载 作者:行者123 更新时间:2023-12-01 06:41:49 26 4
gpt4 key购买 nike

package javajazzup;

public class LoginBean{
String loginid;
String pwd;

public LoginBean(){}

public String getLoginid(){
return loginid;
}
public void setLoginid(String loginid){
this.loginid = loginid;
}
public String getPwd(){
return pwd;
}
public void setPwd(String pwd){
this.pwd = pwd;
}
public String CheckValidUser(){
if(loginid.equals("JavaJazzUp") && pwd.equals("mypwd")){
return "success";
}
else{
return "fail";
}
}
}

最佳答案

您应该将方法 CheckValidUser() 更改为:

    public String CheckValidUser(){
if("JavaJazzUp".equals(loginid) && "mypwd".equals(pwd)){
return "success";
}else{
return "fail";
}
}

关于java - 空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3289631/

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