0

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");
}
halfer
  • 19,824
  • 17
  • 99
  • 186
user3236879
  • 511
  • 2
  • 7
  • 17

2 Answers2

1

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

refer here for more

Community
  • 1
  • 1
Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116
1

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).

Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56
  • I have checked. There is no problem with the class path. – user3236879 Jun 17 '15 at 09:30
  • The problem is with the class loader. The class loader doesn't see you class path. Check it (for example in the Manifest.mf if it is a jar or the WEB-INF/lib directory) – Davide Lorenzo MARINO Jun 17 '15 at 09:39
  • @user3236879 You asked what the exception means, and you got an answer. If you want help troubleshooting your program, you should post your code. Be sure to include the specific string that you're passing to `Class.forname()`. – Kenster Jun 17 '15 at 11:15