5 回答

TA貢獻1876條經驗 獲得超6個贊
使用 JDK 14 的 IntelliJ IDEA 2020.1 也有同樣的問題。
如果您使用 maven ,最后通過在module-info.java下面添加一個這樣的解決方案:src/main/java
module sample {
requires javafx.controls;
requires javafx.graphics;
opens sample;
}

TA貢獻1807條經驗 獲得超9個贊
轉到 Run>Run Configurations 然后 Arguments 選項卡并轉到 VM Arguments 并粘貼以下代碼以添加模塊“--module-path /path/to/lib --add-modules javafx.controls,javafx.fxml”記得修改/path/to/lib 到你的路徑你的圖書館然后點擊應用你就設置好了

TA貢獻1796條經驗 獲得超4個贊
我按照你說的做了,但在那之后我遇到了一些其他的例外,所以我想出了下面的代碼:
module {pkg}{
requires javafx.controls;
requires javafx.graphics;
requires javafx.fxml;
exports {pkg of Application class};
opens {pkg};
}
之后你需要重建你的項目可能是因為 Kotlin 的一些異常。然后我看到異?!拔恢梦丛O置”。要解決此問題,您必須以“/”開頭的 fxml 位置,例如:
App.class.getResource("/form.fxml");
編輯
我在JavaFxHelloWorld使用 Gradle 創建了一個 HelloWorld 項目。

TA貢獻1719條經驗 獲得超6個贊
謝謝,對我來說如下
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
module-info.java:
module sample {
requires javafx.controls;
requires javafx.graphics;
requires javafx.fxml;
opens sample ;
}

TA貢獻1794條經驗 獲得超7個贊
正如marco-rosati在#638 issue 中提出的那樣,如果您使用的是 Maven,則只需添加此插件即可:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine> --add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED </argLine>
</configuration>
</plugin>
添加回答
舉報