| Author |
Classnotfoundexception class.forName()
|
Gina vernon
Ranch Hand
Joined: Jan 16, 2009
Posts: 108
|
|
Hi,
I am trying to use reflection to get a specific instance of a class. But I have found that both class.forName and ClassLoader.loadClass method throw a classnotfoundexception.
here's the code:
stacktrack
Thanks.
|
 |
shan raj
Ranch Hand
Joined: Dec 16, 2008
Posts: 42
|
|
|
Check your class path where you are running program has pointed LDAPManager class or its jar.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
That would probably solve it. I'm wondering why you are loading the class dynamically if you can also load it statically; since you are already using LDAPManager.class, why not simply use LDAPManager.getInstance()? Or is LDAPManager's class loader a custom one (URLClassLoader perhaps), and you want to load the class again? Then I have bad news for you: if the parent class loader could load the class, it already would have, and otherClassInstance == LDAPManager.class (provided it worked). If the parent class loader couldn't load the class before, it still can't now.
So either in the end, otherClassInstance == LDAPManager.class, or there will be a ClassNotFoundException.
To prevent this, either add the JAR file to your class path (in which case you can just use LDAPManager.getInstance()), or create a new class loader to load the class.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Classnotfoundexception class.forName()
|
|
|