aspose file tools
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
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply 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
Bartender

Joined: Oct 01, 2001
Posts: 2542
    
  10

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().
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Problem instantiating an overloaded constructor using Reflections ...
 
Similar Threads
newInstance() doubt
need help with assignment
Reference to objects
How to create object to a specific class by using its name as string variable with out using new.
problem in my Spring Application program