Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Classnotfoundexception class.forName() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Classnotfoundexception class.forName()" Watch "Classnotfoundexception class.forName()" New topic
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Classnotfoundexception class.forName()
 
Similar Threads
connection not possible, even after using the connector
Interface - AbstractClass Collision
Oracle DBConnection Problem
is exist any multi record catalogue? or better to use DB? or array?
Unable to register Derby driver