我遇到 java.lang.NoClassDefFoundError 但我不知道为什么会这样

I'm encounter a java.lang.NoClassDefFoundError and I don't know why it's occuring

我正在尝试编写我的第一个 JavaFX 程序。这是确切的错误行: 错误:找不到或无法加载主 class me.GamingCuber.CPSTest.Main 原因:java.lang.NoClassDefFoundError:javafx/application/Application 但是,我不知道这个错误是怎么发生的。下面是代码:

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

尝试添加参数:

编译

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

运行

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

在 Eclipse 中,我认为您需要导航至菜单:Window > 首选项 > Java > 编译器