wood burning stoves 2.0*
The moose likes Java in General and the fly likes Problem instantiating an overloaded constructor using Reflections ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem instantiating an overloaded constructor using Reflections ..." Watch "Problem instantiating an overloaded constructor using Reflections ..." New topic
Author

Problem instantiating an overloaded constructor using Reflections ...

Aejaz Sheriff
Greenhorn

Joined: Feb 21, 2003
Posts: 2
Problem instantiating an overloaded constructor using Reflections ...
I am trying to access a class by passing its name as string using reflections. There are two class below.The problem is that I am getting a java.lang.IllegalArgumentExceptionwhen I try to call the contructor with arguments.
Any help on this would be appreciated.


Aejaz Sheriff
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

getParameterTypes() returns you an array of classes (Class []). In your case, this array will have one element containing the String class. The newInstance() method expects an array of objects (Object []). What you need to do is create an Object array of size one, and put an actual String (not the String class), or null in there. Then use that array as the parameter to newInstance().
 
GeeCON Prague 2014
 
subject: Problem instantiating an overloaded constructor using Reflections ...