How to Fix NoClassDefFoundError in JavaFX?

情到浓时终转凉″ 提交于 2021-02-05 11:29:33

问题


I'm trying to build a small user interface using JavaFX, But I'm getting an error like this:

Error: Could not find or load main class myApp Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

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();

}

This is the Libraries and jdk I'm using: Image1


回答1:


I think JavaFX is not a part of the JDK > 9 any more. (Your version is 12.x.x)

Probably this could help you: https://openjfx.io/openjfx-docs/#install-javafx

(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.



来源:https://stackoverflow.com/questions/57222894/how-to-fix-noclassdeffounderror-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!