gpt4 book ai didi

程序中的java.lang.NullPointerException

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

我的程序中不断出现以下错误。任何语法或错误都没有问题

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PresentationLayer.AdminLogin.btnLoginActionPerformed(AdminLogin.java:155)
at PresentationLayer.AdminLogin.access$000(AdminLogin.java:11)
at PresentationLayer.AdminLogin$1.actionPerformed(AdminLogin.java:51)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)

这是我的java代码

private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {                                         

String username = txtUsername.getText();
Admin itemObjUserName = new Admin().getLoginDetailsDB(username);

boolean found = (itemObjUserName.getUserName()).equalsIgnoreCase(txtUsername.getText()) && (itemObjUserName.getPassword()).equalsIgnoreCase(txtPassword.getText());
if (found == true) {
String message = "Welcome to the City Library Management System";
JOptionPane.showMessageDialog(this, message);
AdminMenu Obj = new AdminMenu();
Obj.setVisible(true);
this.dispose();

} else {
if (count < 2) {
count = count +1 ;
if (count == 1) {
String message1 = "Invalid Password.!.Warning 2 more Attempts left";
JOptionPane.showMessageDialog(this, message1);
} else if (count == 2) {
String message2 = "Invalid Password.!.Warning 1 more Attempt left";
JOptionPane.showMessageDialog(this, message2);
}
} else {

String message3 = "Invalid Password.! & You are Temporarily Blocked for Exceeding Max Number of Login Attempts.Error";
JOptionPane.showMessageDialog(this, message3);
txtUsername.setVisible(false);
txtPassword.setVisible(false);
btnLogin.setVisible(false);
}
}
}

如果有人能帮助我,我将不胜感激

最佳答案

第 155 行有一个引用(例如 x),该引用为 null,并且您正在调用 x.someMethodx.someField在上面。检查第 155 行,看看那里有什么 null

关于程序中的java.lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22757051/

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