java - @FXML annotation and FXMLLoader class not resolved to a type in Java 11 and JavaFX 11
问题描述
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?
解决方案
FXML(注解、FXMLLoader...)在 Java 9 版本@FXML
中移至模块中。javafx.fxml
在 JavaFX 11 之前,每当您调用与 JavaFX 相关的东西时,您都可以在 SDK 中使用所有 javafx 模块。
但现在你必须包括你需要的:
<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>
请注意,这javafx.controls
取决于javafx.graphics
and java.base
,因此您不需要包括那些。并且javafx.fxml
直接取决于javafx.base
.
推荐阅读
- c# - 如何防止音频重叠?
- regex - 使用正则表达式匹配给定文本中的所有价格
- c# - 将文件发送到 Windows Server
- php - 如何比较 PHP 中的两个 ISO 8061 持续时间?
- javascript - querySelectorAll 返回什么类型的数据?
- c++ - 在 C++11 中生成随机数组
- python - Python Caesar Cipher 样式程序:为什么 python 给我不支持的操作数类型的 TypeError?
- android - 如何存根 Android - 使用 espresso 的 Vision Barcode Scanner
- javascript - 如何使用javascript连续单击多个按钮?
- javascript - Flask 重定向混合内容错误,url 不是 https