好久没摸java了,今天试了一个例子居然报如下错误:
D:\>java Test
Exception in thread "main" java.lang.NoClassDefFoundError: Test
Caused by: java.lang.ClassNotFoundException: Test
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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
Error: Could not find the main class.
Error: A JNI error has occurred, please check your installation and try again
网上的解决方案也很多,我这里导致的原因是java虚拟机找不到.class文件。
设置将.class文件所在路径设置为classpath环境变量即可。
D:\>set classpath=D:
D:\>java Test
This is a test program!
有一本比较好的电子书供大家借鉴:
http://download.csdn.net/detail/wsnzou/5064549