“无法找到或加载主类";尝试在Eclipse中使用JavaFX时 [英] "Could not find or load main class" while trying to use JavaFX in Eclipse

查看:65
本文介绍了“无法找到或加载主类";尝试在Eclipse中使用JavaFX时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java版本1.8.0_221eclipse版本2019-06(4.12.0)我正在尝试制作一个基本的JavaFX程序.我已经将jfxrt外部jar导入到模块构建路径下的"libraries"选项卡中.

我一直收到此错误错误:无法找到或加载主类firstFX.eighthTry由以下原因引起:java.lang.NoClassDefFoundError:javafx/application/Application"

我在网络上发现的唯一建议是告诉我摆脱所有外部jar,但是我需要jfxswt才能使用JavaFX.我也尝试过使用项目">清理",但这也没有做任何事情.

我很茫然,有什么我可以解决的吗?代码在下面

 打包firstFX;导入javafx.application.Application;导入javafx.scene.Scene;导入javafx.scene.control.Button;导入javafx.scene.layout.StackPane;导入javafx.stage.Stage;公开课第八次尝试扩展应用程序{公共静态void main(String [] args){//TODO自动生成的方法存根发射(参数);}@Overridepublic void start(Stage arg0){//TODO自动生成的方法存根arg0.setTitle("Hello World!");final Button btn = new Button();btn.setText("Click Me!");最终StackPane根= new StackPane();root.getChildren().add(btn);arg0.setScene(new Scene(root,300,250));arg0.show();}} 

我已经完成了Eclipse的全新安装(现在是2019-09),并且还通过Help>安装了e(fx)clipse,安装了新软件,然后从本教程.

对于我的代码,我在属性">"Java构建路径">库">模块路径"下添加了JavaFX SDK.然后,将其放在订单和导出"标签的顶部.

不幸的是,这并没有改变任何东西.我仍然遇到与上述相同的错误.

此外,我对需要的外部jar的名称感到误解.从那以后,我用jfxrt.jar替换了jfxswt.jar.但是,这不能解决错误.

解决方案

不确定外观,但是您的班级缺少package firstFX;在名为firstFX ...的文件夹中吗?

java version 1.8.0_221 eclipse version 2019-06 (4.12.0) I'm trying to make a basic JavaFX program. I've imported jfxrt external jar into the libraries tab under module build path.

I've been getting this error "Error: Could not find or load main class firstFX.eighthTry Caused by: java.lang.NoClassDefFoundError: javafx/application/Application"

The only advice I've found around the web tells me to get rid of any external jars, but I need jfxswt in order to use JavaFX. I've also tried to use Project > Clean, but that hasn't done anything either.

I'm at a loss, is there anything I can do to fix this? Code is below

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

public class eighthTry extends Application{

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        launch(args);
    }

    @Override
    public void start(Stage arg0){
        // TODO Auto-generated method stub
        arg0.setTitle("Hello World!");

        final Button btn = new Button();
        btn.setText("Click Me!");

        final StackPane root = new StackPane();
        root.getChildren().add(btn);

        arg0.setScene(new Scene(root, 300, 250));
        arg0.show();

    }

}

Edit: I've done a clean install of Eclipse (now 2019-09) and also installed e(fx)clipse via Help>Install new software then installing both things from http://download.eclipse.org/efxclipse/updates-released/3.3.0/site. I followed this tutorial.

For my code I added the JavaFX SDK under Properties> Java Build Path > Libraries>Module Path. I then put it at the top of the Order and Export tab.

Unfortunately, this hasn't changed anything. I still get the same error as I did above.

Additionally, I was mistaken about the name of the external jar I needed. I have since replaced the jfxswt.jar with jfxrt.jar. However, this has not fixed the error.

解决方案

Not sure how it looks but your class is missing package firstFX; is it in a folder called firstFX... ?

这篇关于“无法找到或加载主类";尝试在Eclipse中使用JavaFX时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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