我在JavaFX应用程序上收到以下错误:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at restaurant.RestaurantListCell$1.handle(RestaurantListCell.java:123)
at restaurant.RestaurantListCell$1.handle(RestaurantListCell.java:1)
导致此错误的方法是以下方法:
@Override
public void updateItem(Restaurant item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null)
setGraphic(null);
else {
open = new Button();
address.setWrappingWidth(250);
open.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Parent pane = null;
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("../detail/RestaurantDetail.fxml"));
DetailController restaurantView = loader.getController();
restaurantView.changeInfo(item);
pane = loader.load();
} catch (IOException e) {
}
Scene table = new Scene(pane);
Stage x = new Stage();
x.setScene(table);
x.show();
}
});
setGraphic(box);
}
}
}
专门导致它的行是restaurantView.changeInfo(item)。我曾尝试在上方硬编码另一家餐厅,并将其传递给changeInfo()方法,但是它不起作用。任何帮助,将不胜感激。谢谢!