JavaFX 空指针异常:需要位置
JavaFX Null Pointer Exception: Location is required
这里是 JavaFX 新手。我正在使用 NetBeans 8.0 IDE 并将我的 FXML 文件 RootLayout.fxml 放在 com.techie.java.view
包中。我正在使用 com.techie.java.controller
包中声明的以下代码加载此 fxml 文件:
private void initRootLayout() {
try {
pane = FXMLLoader.load(ContactManager.class.getResource("/view/RootLayout.fxml"));
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.show();
} catch (IOException ie) {
ie.printStackTrace();
}
}
private void showPersonOverview() {
try {
AnchorPane anchorPane = FXMLLoader.load(ContactManager.class.getResource("/view/PersonOverview.fxml"));
pane.setCenter(anchorPane);
} catch (IOException ie) {
ie.printStackTrace();
}
}
执行时我在 BorderPane pane = FXMLLoader.load(ContactManager.class.getResource("/view/RootLayout.fxml"));
处收到空指针异常。
我做错了什么?
你需要
pane = FXMLLoader.load(
ContactManager.class.getResource("/com/techie/java/view/RootLayout.fxml"));
另一个类似 FXMLLoader
。
这里是 JavaFX 新手。我正在使用 NetBeans 8.0 IDE 并将我的 FXML 文件 RootLayout.fxml 放在 com.techie.java.view
包中。我正在使用 com.techie.java.controller
包中声明的以下代码加载此 fxml 文件:
private void initRootLayout() {
try {
pane = FXMLLoader.load(ContactManager.class.getResource("/view/RootLayout.fxml"));
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.show();
} catch (IOException ie) {
ie.printStackTrace();
}
}
private void showPersonOverview() {
try {
AnchorPane anchorPane = FXMLLoader.load(ContactManager.class.getResource("/view/PersonOverview.fxml"));
pane.setCenter(anchorPane);
} catch (IOException ie) {
ie.printStackTrace();
}
}
执行时我在 BorderPane pane = FXMLLoader.load(ContactManager.class.getResource("/view/RootLayout.fxml"));
处收到空指针异常。
我做错了什么?
你需要
pane = FXMLLoader.load(
ContactManager.class.getResource("/com/techie/java/view/RootLayout.fxml"));
另一个类似 FXMLLoader
。