我正在尝试使用相同的控制器将文本字段中的StudentID设置为新FXML文件的新窗口的标签。但是我得到相同的空指针异常。如何做到这一点?我已经看到了FXML文件具有不同控制器的示例。但是当FXML文件具有相同的控制器时找不到解决方案。预先感谢。
@FXML private Label New_window_label;
@FXML private void StudentID_Submit(actionEvent actionEvent) throws IOException {
if ( Enter_StudentID.getText().matches("[s]\\d+") ){
StudentID = Enter_StudentID.getText();
New_window_label.setText(Enter_StudentID.getText());
Stage stage = (Stage) b_StudentID_Submit.getScene().getWindow();
stage.close();
Stage menu_stage = new Stage();
Parent root = FXMLLoader.load(getclass().getResource("/view/menu.fxml"));
Scene scene = new Scene(root,1100,800 );
menu_stage.setTitle("Main View Window");
menu_stage.setScene(scene);
menu_stage.show();
} else{
StudentID_label.setText("Enter Student ID");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Invalid Student ID");
alert.setHeaderText("Please enter the student ID starting with 's' ");
alert.showAndWait();
}
}