I have a sample class
package temp.com.test;
public class Client{
public String testReflection(String arg1, int arg2, int arg3){
return arg1+arg2+arg3;
}}
Here is my class which perform reflection
public class reflectionTemp{
Method method = null;
public String refImpl(){
try {
Class<?> cls = Class.forName("temp.com.test.Client");
Object obj = cls.newInstance();
Class[] argTypes = new Class[3];
argTypes[0] = Class.forName("Java.lang.String");
argTypes[1] = Integer.TYPE;
argTypes[2] = Integer.TYPE;
Object[] argValues = new Object[3];
argValues[0] = "temp";
argValues[1] = 1;
argValues[2] = 2;
method = cls.getDeclaredMethod("testReflection",argTypes);
Object response = method.invoke(obj, argValues);
}Catch(Exception e){
//do something
}
}
on the line method.invoke(obj, argValues) it is throwing an error java.lang.IllegalArgumentException: wrong number of arguments, couldn't determine where i'm goign wrong any help is appreciated, thanks
Aucun commentaire:
Enregistrer un commentaire