加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 无法从命令行运行swing

发布时间:2020-12-15 01:00:36 所属栏目:Java 来源:网络整理
导读:我在 windows中使用命令行来编译然后执行我的 java程序.我已经去了 http://java.sun.com/docs/books/tutorial/uiswing/start/compile.html并尝试编译HelloWorldSwing.java类.它工作,但当我尝试“java HelloWorldSwing”它给了我一堆错误,并在线程“主”java.
我在 windows中使用命令行来编译然后执行我的 java程序.我已经去了 http://java.sun.com/docs/books/tutorial/uiswing/start/compile.html并尝试编译HelloWorldSwing.java类.它工作,但当我尝试“java HelloWorldSwing”它给了我一堆错误,并在线程“主”java.lang.NoClassDefFoundError:错误的名称:开始/ HelloWorldSwing中说出一些异常的行.

我尝试使用java start / HelloWorldSwing运行,它说noClassDefFoundError.我也没有javac的错误.这是教程中的代码:

import javax.swing.*;        

public class HelloWorldSwing {
    /**
     * Create the GUI and show it.  For thread safety,* this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);

        //Add the ubiquitous "Hello World" label.
        JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

编辑:使用javaw

窗口弹出

“发生Java异常”

另一个窗口

“错误:无法找到主类.
错误:发生了jni错误,请检查您的安装并重试.“

从来没有运行任何java程序的任何问题,我错过了什么?有没有办法知道它是什么?

我也在.java和.class所在的同一路径中运行命令.

我编译程序的路径中没有文件夹启动.

EDIT2
我用java尝试了start / HelloWorldSwing和HelloWorldSwing.

我也没有与javac有任何错误.当我使用javaw并且java给我NoClassDefFoundException时,我得到2个弹出窗口,其中包含我之前输入的消息,然后讨论ClassLoaders和诸如此类的东西.

EDIT3
我通过删除“包开始”让它工作了线.我需要做些什么来使它与它一起工作?

javaw现在也可以删除包行.

解决方法

是的.该页面有一个小错误:

该类使用包,但在运行说明中不使用包

你可以做两件事:

a)删除包名称(删除行pacakge start;)并按指示运行

要么

b)保持包装开始;代码中的一行,并将-d选项附加到javac并使用完整的类名.

我希望这有帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读