0

I'm trying to write my first JavaFX program. This is the exact error line: Error: Could not find or load main class me.GamingCuber.CPSTest.Main Caused by: java.lang.NoClassDefFoundError: javafx/application/Application However, I don't know how this error is occuring. Here is the code down below:

package me.GamingCuber.CPSTest;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }
    
    Button button;
    
    @Override
    public void start(Stage primarystage) throws Exception{
        
        primarystage.setTitle("Test your CPS!");
        button = new Button("Click here for CPS");
        StackPane layout = new StackPane();
        layout.getChildren().add(button);
        
        Scene scene = new Scene(layout, 300, 250);
        primarystage.setScene(scene);
        primarystage.show();
        
    }
    
}

1 Answers1

0

Try adding arguments:

compile

javac --module-path /path/to/java-fx-libs/ --add-modules javafx.controls,javafx.fxml *.java

run

java --module-path /path/to/java-fx-libs/ --add-modules javafx.controls,javafx.fxml MyMainClass

In eclipse I think you need to navigate to Menu: Window > Preferences > Java > Compiler