例如:以下面程序为例:假设此Hello.java文件在D:\Java\下 package A; public class Hello{ public static void main(String args[]){ System.out.println("Hello World!"); } }
D:\Java>javac Hello.java 此程序可以编译通过.接着执行。 D:\Java>java Hello 但是执行时,却提示以下错误! Exception in thread "main" java.lang.NoClassDefFoundError: hello (wrong name: A/Hello) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:537) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) at java.net.URLClassLoader.defineClass(URLClassLoader.java:251) at java.net.URLClassLoader.access$100(URLClassLoader.java:55) at java.net.URLClassLoader$1.run(URLClassLoader.java:194) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:187) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)