【发布时间】:2009-02-03 22:52:49
【问题描述】:
我在 windows 中使用命令行编译然后执行我的 java 程序。我去了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 所在的同一路径中运行命令。
我编译程序的路径中没有文件夹开始。
EDIT2 我用 java 尝试了 start/HelloWorldSwing 和 HelloWorldSwing。
javac 也没有任何错误。当我使用 javaw 和 java 给我 NoClassDefFoundException 时,我得到 2 个弹出窗口,其中包含我之前输入的消息,然后谈论 ClassLoaders 等等。
EDIT3 我通过删除“包开始”让它工作;线。我该怎么做才能让它工作?
javaw 现在也可以工作了,因为我删除了 package 行。
【问题讨论】:
-
您能否粘贴控制台的输出,从您输入“javac etc etc”的位置开始,继续您输入 javac etc.etc 的位置?