【问题标题】:I'm encounter a java.lang.NoClassDefFoundError and I don't know why it's occuring [duplicate]我遇到了 java.lang.NoClassDefFoundError,但我不知道为什么会发生 [重复]
【发布时间】:2022-01-26 01:57:45
【问题描述】:

我正在尝试编写我的第一个 JavaFX 程序。这是确切的错误行: 错误:无法找到或加载主类 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();
        
    }
    
}

【问题讨论】:

  • 也许你可以在这里找到解决方案:stackoverflow.com/questions/16868446/…
  • 我将如何在 Eclipse 中执行此操作?感谢您的回复
  • 好的,我想我现在可以弄清楚了。谢谢大家!
  • 我尝试在我的回答中提供一个小教程。
  • 请遵守 java 命名约定

标签: java javafx


【解决方案1】:

尝试添加参数:

编译

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 > Preferences > Java > Compiler

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多