When I try to run the application by the jar file via the console, during the login event, it gives an exception "java.lang.NullPointerException: Location is required." But when I run the application using the intellij IDE it works fine.
@FXML
public void loginAction(ActionEvent event) throws Exception {
errorLabel.setText("");
authenticate(event);
}
private void authenticate(Event event) throws Exception {
if (validateInput()) {
String username = userName.getText().trim();
User user = UserDAO.searchUserByName(username);
if (user == null) {
userName.setText("");
password.setText("");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Login Error");
alert.setHeaderText("Failure message");
alert.setContentText("Invalid username!!");
alert.showAndWait();
} else {
String userPassword = user.getPassword();
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(password.getText().getBytes());
byte byteData[] = md.digest();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++) {
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
}
String role = user.getRole();
String id = user.getUserId();
sessionRole = role;
userId = id;
if (sb.toString().equals(userPassword)) {
if (role.equals("Admin")) {
windows("../views/admin.fxml", "Admin Dashboard");
} else {
windows("../views/pos.fxml", "Point of Sales");
}
} else {
userName.setText("");
password.setText("");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Login Error");
alert.setHeaderText("Failure message");
alert.setContentText("Invalid password!!");
alert.showAndWait();
}
}
}
}
private void windows(String path, String title) throws Exception {
Stage stage;
Parent root;
root = FXMLLoader.load(getClass().getResource(path));
stage = (Stage) loginButton.getScene().getWindow();
Scene scene = new Scene(root);
stage.setTitle(title);
stage.setScene(scene);
stage.show();
}
it gives the exception to the line:
windows("../views/admin.fxml", "Admin Dashboard");
I tried to give the absolute path also for the fxml file. It only occurs when I run the application using the jar file. No file is missing in the jar also. What can be the cause of this. Thanks in advance.