views:

40

answers:

1

hi, i load a class using ClassLoader but i am not able to create an object of that class.Here is the code.What is the problem?Help

Cloader = new URLClassLoader(new URL[] {new File(binfolderurl).toURI().toURL()},ClassLoader.getSystemClassLoader);

Thread.currentThread().setContextClassLoader(Cloader);

Class clss = Cloader.loadClass("Someclass");

Object myobj =  clss.newInstance();
A: 

You should be getting an Exception, describing what did not work. Did you?

The most likely reason is the class not having a default (no-arg) constructor, or that constructor being not public.

Thilo
i didnt get any exception.i have defined default constructor
Steven
And the class needs to be public.
Tom Hawtin - tackline
If you did not get any exception, what exactly did not work?
Thilo
after instantiation i use the object to invoke a method which is not happenening
Steven
the class is public
Steven
if you get an object, then the newInstance() worked. What do you mean by "invoking a method is not happening"?
Thilo
am not getting the object itself
Steven