尝试关闭当前场景并在选择menuItem时打开另一个场景时出现问题。我的主要阶段编码如下:
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Shop Management");
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("cartHomePage.fxml"));
Pane myPane = (Pane) myLoader.load();
CartHomePageUI controller = (CartHomePageUI) myLoader.getController();
controller.setPrevStage(primaryStage);
Scene myScene = new Scene(myPane);
primaryStage.setScene(myScene);
primaryStage.show();
}
执行该程序后,它将转到cartHomePage.fxml。选择菜单项后,我可以从那里选择创建产品或创建类别。这是我的动作事件:
Stage prevStage;
public void setPrevStage(Stage stage){
this.prevStage = stage;
}
public void gotoCreateCategory(ActionEvent event) throws IOException {
Stage stage = new Stage();
stage.setTitle("Shop Management");
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("createCategory.fxml"));
Pane myPane = (Pane) myLoader.load();
Scene scene = new Scene(myPane);
stage.setScene(scene);
prevStage.close();
setPrevStage(stage);
stage.show();
}
//Method to change scene when menu item create product is on click
@FXML
public void gotoCreateProduct(ActionEvent event) throws IOException {
Stage stage = new Stage();
stage.setTitle("Shop Management");
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("creatProduct.fxml"));
Pane myPane = (Pane) myLoader.load();
Scene scene = new Scene(myPane);
stage.setScene(scene);
prevStage.close();
setPrevStage(stage);
stage.show();
}
但是,我只能切换一次舞台。例如,我的默认页面是cartHomePage.fxml。运行程序时,首先要创建产品阶段。在那之后,我不能再去任何地方了。错误消息是:
java.lang.IllegalStateException: Location is not set.
and Null Pointer Exception
我关上台并绕过它之后才做好了准备。我想知道哪一部分出错了。
提前致谢。
MMMHUHU
慕神8447489
相关分类