I have been experiencing this strange problem for a while. I am making a JavaFX application that has a login screen.
The problem is that whenever I press the enter key after entering the username and password, I encounter the following fatal error. It works fine if I use the Login button.
#
The full error log is here .
The following are the steps for the username and password fields that the ENTER key detects:
fieldUsername.setOnKeyPressed((KeyEvent event) -> { if (event.getCode() == KeyCode.ENTER) { KeyEvent.fireEvent(buttonLogin, new MouseEvent(MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, MouseButton.PRIMARY, 1, true, true, true, true, true, true, true, true, true, true, null)); } }); fieldPassword.setOnKeyPressed((KeyEvent event) -> { if (event.getCode() == KeyCode.ENTER) { KeyEvent.fireEvent(buttonLogin, new MouseEvent(MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, MouseButton.PRIMARY, 1, true, true, true, true, true, true, true, true, true, true, null)); } });
I launch the login button each time I press the ENTER key.
And the following is the action listener for buttonLogin :
buttonLogin.setOnMouseClicked((MouseEvent event) -> { CheckLoginAndPin c1 = new CheckLoginAndPin(); if (!fieldUsername.getText().isEmpty() && !fieldPassword.getText().isEmpty()) { if (c1.checkUsername(fieldUsername.getText())) { if (c1.login(fieldUsername.getText(), fieldPassword.getText())) { ArrayList<String> arrayListGetUserDetails = c1.getPriviledge(fieldUsername.getText()); stageLogin.close(); MainFrame mainFrame = new MainFrame(arrayListGetUserDetails.get(0), arrayListGetUserDetails.get(1), arrayListGetUserDetails.get(2), fieldUsername.getText()); } else { PopupErrorMessage popupErrorMessage = new PopupErrorMessage(stageLogin, "Password incorrect", fieldPassword, 100, 60); } } else { PopupErrorMessage popupErrorMessage = new PopupErrorMessage(stageLogin, "User name incorrect", fieldUsername, 100, 60); } } else { if (fieldUsername.getText().isEmpty() && !fieldPassword.getText().isEmpty()) { PopupErrorMessage popupErrorMessage = new PopupErrorMessage(stageLogin, "User name can not be empty", fieldUsername, 100, 60); } else if (fieldPassword.getText().isEmpty() && !fieldUsername.getText().isEmpty()) { PopupErrorMessage popupErrorMessage = new PopupErrorMessage(stageLogin, "Password can not be empty", fieldPassword, 100, 60); } else if (fieldUsername.getText().isEmpty() && fieldPassword.getText().isEmpty()) { PopupErrorMessage popupErrorMessage = new PopupErrorMessage(stageLogin, "User name & password can not be empty", fieldUsername, 100, 60); } } });
JDK - Oracle Java 8 Update 91
OS - Ubuntu 16.04 LTS 64-bit
IDE - Netbeans IDE 8.0.2
What am I doing wrong here?