2 回答

TA貢獻1830條經驗 獲得超3個贊
解決方案幾乎在堆棧跟蹤中提到;問題縮小到它告訴您缺少的導出的程度:
...
Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class com.teachersdunet.hellojavafx.HelloApp (in module com.teachersdunet.hellojavafx) because module com.teachersdunet.hellojavafx does not export com.teachersdunet.hellojavafx to module javafx.graphics
...
將以下行添加到com.teachersdunet.hellojavafx模塊中:
module com.teachersdunet.hellojavafx {
...
exports com.teachersdunet.hellojavafx;
}
或者只授予對單個模塊的訪問權限:
module com.teachersdunet.hellojavafx {
...
exports com.teachersdunet.hellojavafx to javafx.graphics;
}

TA貢獻1825條經驗 獲得超6個贊
你會收到這樣的錯誤,因為你沒有在 start 方法中調用任何東西。您必須設置Scene并提供FXML文件的目錄。
我已經更正了你的代碼。
package com.teachersdunet.hellojavafx;
import javafx.application.Application;
import javafx.stage.Stage;
public class HelloApp extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
try {
Parent root = FXMLLoader.load(getClass().getResource("directory_of_your_fxml_file"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
我希望這有幫助。
添加回答
舉報