使用javafx编程时出现javafx.fxml.LoadException

时间:2016-01-07 13:11:13

标签: java exception javafx

我是javafx的新手,并试图弄清楚是什么。一切顺利,但后来遇到了异常。这是我的代码;

.catergory-classes .portfolio-item:hover > .hover-item{
    background-color:#000000;
}

我在

获得了一个LoadExcepiton
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();
        }
    }

任何人都知道为什么? 堆栈跟踪----

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

谢谢。

1 个答案:

答案 0 :(得分:1)

错误消息表明控制器类中的字段类型与fxml文件中声明的类型不匹配。具体来说,您的控制器声明了一个名为MainApp的{​​{1}}类型的字段,但您的fxml文件正在尝试将mainApp注入该字段。