jQuery in Action, 3rd edition
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


Win a copy of Building Microservices this week in the Design forum!
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: 2931
    
  12

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Problem instantiating an overloaded constructor using Reflections ...
 
It's not a secret anymore!