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();
            }
        });
    }
}

编辑:使用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并使用完整的类名.

我希望这有帮助.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...