我的第一个场景正常但是当我尝试使用第二个场景时它会崩溃。我想我做错了什么?说我喜欢设置Root,但尝试了很多不同的东西,没有用,不断崩溃
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("visual.fxml"));
Parent root = (Parent) loader.load();
ctrl = loader.getController();
primaryStage.setTitle("World of Snopscraft");
primaryStage.setScene(new Scene(root, 1024, 768));
primaryStage.show();
ctrl.setPrevStage(primaryStage);
}
控制器:
boolean canSetCard=false;
int selectedCard;
Game game;
Stage primaryStage;
@FXML
public void initialize() {
game=new Game(this);
game.start();
};
public void setScene() throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("end.fxml"));
primaryStage.setScene(new Scene(root, 1024, 768));
primaryStage.show();
}
public void setPrimaryStage(Stage primaryStage) {
this.primaryStage = primaryStage;
}
public void playCard1(){
try {
setScene();
} catch (IOException e) {
e.printStackTrace();
}
//if(game.getCanPlay()==true)game.play(0);
}
编辑:添加了错误代码和控制器 错误:
Javafx.fxml.LoadException: Root hasn't been set. Use method setRoot() before load.
/C:/Users/Rene/IdeaProjects/snops/out/production/snops/sample/end.fxml:11