【50期】基础考察:ClassNotFoundException 和 NoClassDefFoundError 有什么区别
来自:cnblogs.com/duke2016/p/9153241.html
ClassNotFoundException
public class MainClass {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at MainClass.main(MainClass.java:7)
NoClassDefFoundError
public class TempClass {
}
public class MainClass {
public static void main(String[] args) {
TempClass t = new TempClass();
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: TempClass
at MainClass.main(MainClass.java:6)
Caused by: java.lang.ClassNotFoundException: TempClass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
总结
相关文章