我遵循了关于 StackOverflow Passing Parameters JavaFX FXML的另一个答案的建议,但是当我尝试运行我的程序时,我得到了一个空指针异常。
我有代码可以创建一个新工作人员并启动一个线程,然后尝试显示一个分析器对话框。但是,此对话框无法正确打开。
@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);
}
showProfilerDialog 如下:
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;
}
initProgress 如下:
public void initProgress(PDBProfilerOperator operator) {
this.profilingFiles.progressProperty().bind(operator.progressProperty());
}
尝试运行 initProgress 时出现 NullPointerException,因为控制器仍为 Null。如何修复此错误?
谢谢!