Android examples for java.lang.reflect:Method Invoke
invoke object's method with a single param
import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main{ /**/*from w w w.ja v a2 s. c om*/ * invoke object's method with a single param * @param Object: Object to be use * @param methodName: method to be invoke * @param argsClass: parameter's type * @param args: arguments * by lixl */ public static Object invokeObjectMethod(Object o, String methodName, Class[] argsClass, Object[] args) { Object returnValue = null; try { Class<?> c = o.getClass(); Method method; method = c.getMethod(methodName, argsClass); returnValue = method.invoke(o, args); } catch (Exception e) { // TODO Auto-generated catch block // ExceptionHandler.processFatalException(e); } return returnValue; } }