Issue
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
Solution
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.
Answered By - aslary