我一直在我的程序中出現錯誤。沒有什麼錯與任何SYNTEXT或任何錯誤也程序中的java.lang.NullPointerException
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? – Salah
錯誤是第155行,在那裏設置斷點並檢查哪個對象爲空。然後確定它爲什麼是空的。 – Fredrik
@Sala 線155是本 (itemObjUserName.getUserName())equalsIgnoreCase(txtUsername.getText())&&(itemObjUserName.getPassword())equalsIgnoreCase(txtPassword.getText())。。如果(found == true) – user3003900