无法从命令行运行swing

6 java swing

我在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();
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:使用javaw

窗口弹出

"发生Java异常"

另一个窗口

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

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

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

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

EDIT2我尝试使用java启动/ HelloWorldSwing和HelloWorldSwing.

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

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

javaw现在也可以删除包行.

Osc*_*Ryz 2

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

类使用了包,但是在运行指令中没有使用包

你可以做两件事:

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

或者

b) 将该package start;行保留在代码中,并将-d选项附加到javac并使用完整的类名称。

我希望这有帮助。