I followed the advice of another answer on StackOverflow Passing Parameters JavaFX FXML, but when I attempted to run my program, I got a null pointer exception.
I have code that makes a new worker and starts a thread and then attempts to show a profiler dialog. However, this dialog does not open properly.
@FXML
private void profilePDBFoldertoCSVAction(ActionEvent e) {
PDBProfilerOperator worker = new PDBProfilerOperator();
FileChooser fc = new FileChooser();
DirectoryChooser dc = new DirectoryChooser();
Stage s = new Stage();
worker.setPdbsdirectory(dc.showDialog(s));
worker.setOutputCSV(fc.showSaveDialog(s));
Thread th = new Thread(worker);
th.setDaemon(true);
th.start();
worker.showProfilerDialog(worker);
}
The showProfilerDialog is the following:
public Stage showProfilerDialog(PDBProfilerOperator operator) {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/pdpro/gui/dialogues/dataset/ProfilingProgress.fxml"));
ProfilingProgressController controller = loader.<ProfilingProgressController>getController();
controller.initProgress(operator);
Parent root = null;
try {
root = (Parent) loader.load();
} catch (IOException ex) {
Logger.getLogger(PDPro.class.getName()).log(Level.SEVERE, null, ex);
}
Scene scene = new Scene(root);
Stage stage = new Stage();
stage.setScene(scene);
stage.setTitle("Profiling Progress");
stage.show();
return stage;
}
And the initProgress is the following:
public void initProgress(PDBProfilerOperator operator) {
this.profilingFiles.progressProperty().bind(operator.progressProperty());
}
I get a NullPointerException when attempting to run the initProgress since the controller remains Null. How do I fix this error?
Thanks!