ClassNotFoundException when load class with Class.forName

3k Views Asked by At

When I using the Class.forName to load a class, there is an exception

ClassNotFoundException

Do you know what may be reason?

Class<?> cl;
try {
    cl = Class.forName("com.qti.server.power.ShutdownOem");
}
catch(ClassNotFoundException e) {
    Log.d("localdebug", "testLoadClass ClassNotFoundException com.qti.server.power.ShutdownOem");
}
2

There are 2 best solutions below

4
On

Class.forName() only accepts fully-qualified names, secondly class may not be present at the time of loading into classloaders

refer here for more

3
On

ClassNotFoundException occurs when class loader could not find the required class in class path.

Check your class path and add the class in the classpath. The class name must be fully qualified (with packages).