我遇到了一个非常基础的问题。我使用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);
}
}