如何修复JavaFX中的NoClassDefFoundError? [英] How to Fix NoClassDefFoundError in JavaFX?
问题描述
我正在尝试使用JavaFX构建一个小的用户界面,但是却出现了这样的错误:
I'm trying to build a small user interface using JavaFX, But I'm getting an error like this:
错误:找不到或加载主类myApp,原因是:java.lang.NoClassDefFoundError:javafx/application/Application
Error: Could not find or load main class myApp Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
这是我的代码:和即时通讯使用jdk 12.0.2
This is my code: and im using jdk 12.0.2
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class myApp extends Application{
public static void main(String[] args) {
Phonebook mybook = new Phonebook();
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Group group = new Group();
Scene scene = new Scene(group, 600, 300);
scene.setFill(Color.GRAY);
primaryStage.setTitle("Phone Book");
primaryStage.setScene(scene);
primaryStage.show();
}
这是我正在使用的库和jdk:图片1
This is the Libraries and jdk I'm using: Image1
推荐答案
我认为JavaFX不再是JDK> 9的一部分.(您的版本是12.x.x)
I think JavaFX is not a part of the JDK > 9 any more. (Your version is 12.x.x)
这可能会帮助您: https://openjfx.io/openjfx-docs/#install-javafx
(假设您正在使用Maven)如果这样做没有帮助,请尝试清理并构建您的应用程序.有时Maven无法识别新添加的依赖项.
(Assuming you are using Maven) If this does not help, try to clean and build your Application. Sometimes Maven does not recognize newly added dependencies.
这篇关于如何修复JavaFX中的NoClassDefFoundError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!