Problem instantiating an overloaded constructor using Reflections ...
posted 12 years ago
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.
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().