/ / javafxでプログラミング中にjavafx.fxml.LoadException-java、exception、javafx

javafxでプログラミング中のjavafx.fxml.LoadException - java、exception、javafx

私はjavafxが初めてで、何が何であるかを理解しようとしています。それはうまくいっていましたが、その後例外が発生しました。これは私のコードです。

public void showPersonOverview() {
try {
// Load person overview.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("/AddressAppView/PersonOverview.fxml"));
AnchorPane personOverview = (AnchorPane) loader.load();

// Set person overview into the center of root layout.
rootLayout.setCenter(personOverview);

// Give the controller access to the main app.
PersonOverviewController controller = loader.getController();
controller.setMainApp(this);

} catch (IOException e) {
e.printStackTrace();
}
}

そして、私はLoadExcepitonを取得します

AnchorPane personOverview = (AnchorPane) loader.load();

誰にも理由がありますか? スタックトレース - -

javafx.fxml.LoadException:
/home/mert/workspace/AddressApp/bin/AddressAppView/PersonOverview.fxml:25

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at AddressAppController.MainApp.showPersonOverview(MainApp.java:77)
at AddressAppController.MainApp.start(MainApp.java:47)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Can not set AddressAppController.MainApp field AddressAppView.PersonOverviewController.mainApp to javafx.scene.layout.AnchorPane
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163)
at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:857)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:751)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 13 more

ありがとうございました。

回答:

回答№1は1

エラーメッセージは、コントローラークラスのフィールドの型がfxmlファイルで宣言された型と一致しないことを示しています。具体的には、コントローラーはタイプのフィールドを宣言します MainApp と呼ばれる mainApp、しかし、あなたのfxmlファイルは AnchorPane その分野に。