Android examples for java.lang.reflect:Method Invoke
invoke Non Static Method
//package com.java2s; import java.lang.reflect.Method; import android.util.Log; public class Main { private static final String TAG = "loader"; public static Object invokeNonStaticMethod(Object obj, Class[] type, String methodname, Object[] args) { try {//from w w w. j a va 2 s .c om Method method = obj.getClass().getDeclaredMethod(methodname, type); if (method == null) return null; method.setAccessible(true); return method.invoke(obj, args); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); return null; } } public static Class getClass(String name) { try { return Class.forName(name); } catch (ClassNotFoundException e) { Log.e(TAG, e.getMessage(), e); return null; } } }