I have written a class loader that will load class only form a specified directory.This classLoader is a able to load classes but then i am not able to create an instance of the class that was loaded after i get the Class reference of the loaded class using classref.newInstance() i get class not found exception. What is the way around this ???
Are you sure you've loaded the class in the first place? It seems extremely odd that you would get a ClassNotFoundException from the newInstance() method, after the Class object has already been created. Especially since ClassNotFoundException is a checked exception which cannot be thrown by newInstance(). I suggest you re-check exactly which line is throwning the exception, and exactly what does the message say. Also check to see if you really have created a Class object - insert a line like <code><pre> System.out.println("The class object is " + classref);</pre></code> The other possibility is that newInstance() will not work if there is no public no-argument constructor for your class. You may need to use the getConstructor(Class) method of Class to obtain an appropriate Constructor, and then use the newInstance(Object) method of Constructor to instantiate the class using any needed initial arguments.
"I'm not back." - Bill Harding, Twister
Joined: Nov 21, 2000
hey thanks Jim Yingst it worked when i added a public no aug constructor. Now is there a way to actually register my classloader with the jvm such that my class loader gets precedence over the bootstrap classloader?