1 回答
TA贡献1866条经验 获得超5个赞
所以有很多错误(夸大效果),但你正在学习,所以我会尽力提供帮助。请在复制并粘贴到您的程序之前阅读全部内容,以便您理解它
从你得到一个空指针的原因开始,你有一个事实,extend DashBoardUserController这意味着DashBoardUserController程序初始化时没有与你交谈TheatresController,当你尝试访问它时,它给了你一个空指针,因为没有初始化在扩展类
所以第 1 步删除extend DashBoardUserController
因此,既然它已经消失了,我们需要获取DashBoardUserController对该类的引用,以便它可以调用必要的方法,我们可以在初始化时TheatresController这样做
FXMLLoader loader = new FXMLLoader(getClass().getResource(resourceLocation));
Pane pane = loader.load();
TheatresController controller = loader.getController();
controller.setDashBoardUserControllerReference(this);//We'll get here
接下来是在中制作必要的方法和变量TheatresController
private DashboardUserController dashboardUserController;//Set at top of class
public void setDashBoardUserControllerReference(DashboardUserController dashboardUserController){
this.dashboardUserController = dashboardUserController;
}
完成这将修复空指针移动以生成您的方法,因为有很多代码复制对您来说是不必要的输入
@FXML
public void onjosephclick() {
//weekPickerInput(); //You can delete from here
//addFilmsInList();
//filmList.setShowLocation("Joseph P");
//System.out.println("joseph button pressed");
//try {
// Pane pane = FXMLLoader.load(getClass().getResource("scenes/josephpane.fxml"));
// seatsSelection.getChildren().setAll(pane);
//} catch (IOException e) {
// System.out.println(e);
//}
//setStuff();
//seatsavailable.setText(Integer.toString(seatsJoseph));
//filmPrice = filmList.searchFilm().get().getPrice();
//System.out.println("Price:"+filmPrice); //Down to here
genericOnClick("Joseph P","scenes/josephpane.fxml",seatsJoseph);
//change the strings for each call and remove the unnecessary stuff
//in the methods it will clean it up a lot
}
private void genericOnClick(String location, String resourceLocation, int seats) {
weekPickerInput();
addFilmsInList();
filmList.setShowLocation(location);
System.out.println("Location:"+location);
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(resourceLocation));
Pane pane = loader.load();
TheatresController controller = loader.getController();
controller.setDashBoardUserControllerReference(this);
seatsSelection.getChildren().setAll(pane);
} catch (IOException e) {
System.out.println(e);
}
setStuff();
seatsavailable.setText(Integer.toString(seats));
filmPrice = filmList.searchFilm().get().getPrice();
System.out.println("Price:"+filmPrice);
}
最终要学习的其他一些东西是 java 命名约定,处理代码复制
祝好先生好运代码。如果它不起作用,我可以发布完整的课程,但我认为您应该尝试将其找出为它的好习惯,我给了您所有您需要的代码,如果您需要更多帮助,请告诉我
添加回答
举报