首页 > 解决方案 > 为什么登录成功后还是会出现“Incorrect account or password or user type”?

问题描述

我已经尝试过,但无法弄清楚为什么,如果有任何解决方案,感谢您的帮助JFrame

if (userInfo != null ) {    
    JOptionPane.showMessageDialog(null, "LoginSuccessful");
    dispose();                  
    new ChooseRoomFrame(userInfo,UserRoomDetails,UserDao).setVisible(true);
}                   
if(Staff != null & rdbtnStaff.isSelected()){
    JOptionPane.showMessageDialog(null, "Login Successful");
    dispose();
    new StaffFrame(userInfo, UserRoomDetails,UserDao).setVisible(true);                 
}       
if(user.isEmpty() & pwd.isEmpty()){
    JOptionPane.showMessageDialog(null,"Please insert Username and Password");
}               
else if(user.isEmpty()){
    JOptionPane.showMessageDialog(null,"Please insert Username");
}
else if (pwd.isEmpty()){
    JOptionPane.showMessageDialog(null,"Please insert Password");
}   
else {
    JOptionPane.showMessageDialog(null, "Incorrect account or password or user type");
}

标签: javaswingjframe

解决方案


由于您正在检查密码或用户名是否为空,因此当用户和密码不为空时,将执行最后的 else 语句。

else {
       JOptionPane.showMessageDialog(null, "Incorrect account or password or user type");
}  

删除此 else 语句,您的代码将按预期工作。

这是因为您已经涵盖了一个或两个字段为空的情况。这意味着缺少 if 的最终 else 将在它们不为空时执行。


推荐阅读