错误:找不到或加载主类应用程序.主JAVAFX [英] Error: Could not find or load main class application.Main JAVAFX

查看:881
本文介绍了错误:找不到或加载主类应用程序.主JAVAFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目属性下的Java Build Path Libraries下,我在Modulepath下有一个名为javafx12的用户库.

Under Java Build Path Libraries under the properties of my project, I have my User Library called javafx12 under Modulepath.

这删除了与导入javafx有关的所有错误,但未解决.

This removed all the errors regarding import javafx not resolved.

当我尝试运行我的项目时,我得到

When I try to run my project, I get

错误:无法找到或加载主类应用程序. 由以下原因引起:java.lang.NoClassDefFoundError:javafx/application/Application"

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

如何摆脱这个错误?

我正在使用Java SE 12或JDK 12.

I am using Java SE 12 aka JDK 12.

我也在使用eclipse.

I am using eclipse as well.

    package application;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = new BorderPane();
            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

类文件中没有错误.

推荐答案

在@Ashish链接openjfx.io/openjfx-docs

Following @Ashish link openjfx.io/openjfx-docs

我执行了以下操作,并修复了该错误:

I did the following and it fixed the error:

  1. 添加VM参数 要解决该问题,请单击运行->运行配置...-> Java应用程序,为名为hellofx的项目创建一个新的启动配置,并添加以下VM参数:
  1. Add VM arguments To solve the issue, click on Run -> Run Configurations... -> Java Application, create a new launch configuration for your project named hellofx and add these VM arguments:

Linux/Mac Windows

Linux/Mac Windows

-模块路径"\ path \ to \ javafx-sdk-12.0.1 \ lib" --add-modules javafx.controls,javafx.fxml 警告:请确保以下选项:

--module-path "\path\to\javafx-sdk-12.0.1\lib" --add-modules javafx.controls,javafx.fxml Warning: Make sure the option:

在使用SWT启动时使用-XstartOnFirstThread参数 未选择. VM参数单击应用",然后关闭对话框.

Use the -XstartOnFirstThread argument when launching with SWT is not selected. VM arguments Click apply and close the dialog.

这篇关于错误:找不到或加载主类应用程序.主JAVAFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆