@FXML annotation and FXMLLoader class not resolved to a type in Java 11 and JavaFX 11

坚强是说给别人听的谎言 提交于 2019-12-02 11:15:58

问题


Earlier my project used to be on Java 8 but now I am using Java 11 along with JavaFX 11 and now JavaFX has been decoupled from Java since Java 11. I haven't download the JavaFX SDK but added below dependency in pom.xml for getting required modules and jar files which were used to be part of Java itself in earlier versions.

       <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>

But I am getting compilation error can not be resolved to a type on @FXML annotation and FXMLLoader class.

Do I need to add some other/extra dependencies to resolve this issue?


回答1:


FXML (@FXMLannotation, FXMLLoader...) were moved to the module javafx.fxml with the Java 9 release.

Before JavaFX 11, whenever you were calling something JavaFX related, you had all the javafx modules available within the SDK.

But now you have to include the ones you need:

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>11</version>
</dependency>

Note that javafx.controls depends on javafx.graphics and java.base, so you don't need to include those. And javafx.fxml directly depends on javafx.base.



来源:https://stackoverflow.com/questions/52603396/fxml-annotation-and-fxmlloader-class-not-resolved-to-a-type-in-java-11-and-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!