Friday, 1 August 2014

ClassNotFoundException

ClassNotFoundException is a checked exception, thrown when an Application tries to load the class using name, but the class doesn't exist.

public class LoadClass {
    public static void main(String args[]) throws ClassNotFoundException{
        Class.forName("NoClass");
    }
}

Since there is no class named 'NoClass', so ClassNotFoundException thrown.

Exception in thread "main" java.lang.ClassNotFoundException: NoClass
 at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:259)
 at LoadClass.main(LoadClass.java:3)
Java Result: 1

ClassNotFoundException may thrown while application tries to use the below methods.
      Class.forName(java.lang.String),
      ClassLoader.findSystemClass(java.lang.String), 
      ClassLoader.loadClass(java.lang.String, boolean)




                                                             Home

No comments:

Post a Comment