我使用Windows中的命令行来编译然后执行我的java程序。我去了http://java.sun.com/docs/books/tutorial/uiswing/start/compile.html http://java.sun.com/docs/books/tutorial/uiswing/start/compile.html并尝试编译 HelloWorldSwing.java 类。它有效,但是当我尝试“java HelloWorldSwing”时,它给了我一堆错误,并说了一些类似于线程“main”java.lang.NoClassDefFoundError:HelloWorldSwing(错误名称:start/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 所在的同一路径中运行该命令。
我编译程序的路径中没有文件夹 start 。
编辑2
我用 java 尝试了 start/HelloWorldSwing 和 HelloWorldSwing。
我也没有收到 javac 的任何错误。当我使用 javaw 时,我会收到 2 个弹出窗口,其中包含我之前输入的消息,而 java 给了我 NoClassDefFoundException,然后讨论了 ClassLoaders 之类的内容。
编辑3
我通过删除“package start;”来让它工作。线。我需要做什么才能让它发挥作用?
既然我删除了包行,javaw 也可以工作了。