?
=?iso-8859-1?B?bW9vcJk=?=
Hi,
I use this class to call methods of other classes:
public class FunctionHandler {
public static String execRoutine(String longName, List<String> args)
throws Exception {
String ret;
int dot = longName.lastIndexOf('.');
String className = longName.substring(0, dot);
String funcName = longName.substring(dot + 1);
printf("class name: " + className);
printf("func name: " + funcName);
Class c = Class.forName(className);
Method routine = c.getMethod(funcName, List.class);
printf("method: " +
routine.getGenericParameterTypes()[0].toString());
ret = (String) routine.invoke(args);
return ret;
}
}
And this is the class whose method is going to be called:
public class Math {
public static String C(List<String> args) {
int n, r;
n = Integer.parseInt(args.get(0));
r = Integer.parseInt(args.get(1));
Combination c = new Combination(n, r);
return String.valueOf(c.getTotal());
}
}
But I got the following exception:
java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
com.gsta.enrus.services.el.FunctionHandler.execRoutine(FunctionHandler.java:23)
Why?
I use this class to call methods of other classes:
public class FunctionHandler {
public static String execRoutine(String longName, List<String> args)
throws Exception {
String ret;
int dot = longName.lastIndexOf('.');
String className = longName.substring(0, dot);
String funcName = longName.substring(dot + 1);
printf("class name: " + className);
printf("func name: " + funcName);
Class c = Class.forName(className);
Method routine = c.getMethod(funcName, List.class);
printf("method: " +
routine.getGenericParameterTypes()[0].toString());
ret = (String) routine.invoke(args);
return ret;
}
}
And this is the class whose method is going to be called:
public class Math {
public static String C(List<String> args) {
int n, r;
n = Integer.parseInt(args.get(0));
r = Integer.parseInt(args.get(1));
Combination c = new Combination(n, r);
return String.valueOf(c.getTotal());
}
}
But I got the following exception:
java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
com.gsta.enrus.services.el.FunctionHandler.execRoutine(FunctionHandler.java:23)
Why?