【发布时间】:2019-04-18 13:11:33
【问题描述】:
我遇到了一个非常基本的问题。我使用 JavaFX 创建了一个简单的 hello world 程序,它在 JDK 1.8 上运行良好。但是当我切换到 JDK-11 时,它会抛出以下异常:
Error: Could not find or load main class application.Main
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
以下是我在eclipse中写的代码
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
private Scene theScene;
@Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("MyScene.fxml"));
Parent mainPane = loader.load();
theScene = new Scene(mainPane);
primaryStage.setScene(theScene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public void setTheScene(Scene theScene) {
this.theScene = theScene;
}
public static void main(String[] args) {
launch(args);
}
}
【问题讨论】:
-
你在哪里以及如何运行它(在 eclipse/Intellij 中,作为 JAR 等)?
-
我正在使用“java -jar myapp.jar”运行 jar 文件
-
你是如何构建 jar 的?
-
Java 11 不包含 JavaFX 11,但这并不意味着它不支持它。您可以运行 JavaFX 11 应用程序,并且有一个入门指南here。