嘿,我在 Eclipse 中写了一个简单的程序:
package hw;
public class Assignment02Q01Sec01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
if (args.length == 0) {
System.out.println("No arguments!");
return;
}
System.out.println(args[args.length - 1].charAt(args[args.length -1].length() - 1));
}
}
在 Eclipse 中选择“运行”菜单时运行良好,但从命令行运行时失败:
c:\Users\ghostcow\workspace\hw\bin\hw>java Assignment02Q01Sec01
Exception in thread "main" java.lang.NoClassDefFoundError: Assignment02Q01Sec01
(wrong name: hw/Assignment02Q01Sec01)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
我究竟做错了什么?
注意:我在 cmd 中的类路径中,并且 '.' 包含在 CLASSPATH 环境变量中,我检查了。
编辑:谢谢,问题解决了。