I encounter this problem at several places in my application. 1) I have one Window with a textfield and a button. On clicking, a function is executed that uses the input of the textfield. Everything works till here. 2) I link the button instead to a 2nd window that opens when clicking. In the 2nd window I create a button that executes the same function as in in 1 ), still utilizing the Textfield in the 1st window. I get a java.lang.NullPointerException. Both windows are still open and are linked to the same controller class.
What's the issue here and how can I solve it? Thank you for your help!
@FXML
private TextField DeleteIdText;
@FXML
private Button DeleteOrderBtn;
@FXML
private Button DeleteYesBtn;
//This is the code I use to open the 2nd window:
@FXML
public void openDeleteConfirmation(){
try {
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("/Menu/ConfirmDeleteView.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
System.out.println("exception" + e);
e.printStackTrace();
}
// This is the function I try to execute:
@FXML
public void deleteDish(ActionEvent event) throws SQLException, ClassNotFoundException {
// TODO Autogenerated
try {
MenuDAO.deleteDish(DeleteIdText.getText());
} catch (SQLException e) {
System.out.println("Error occurred while deleting item \n" + e);
throw e;
}