Android examples for java.lang.reflect:Constructor
get Object By Constructor
import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main{ /*from www. j a v a 2 s. c om*/ public static Object getObjectByConstructor(String className, Class[] intArgsClass, Object[] intArgs) { Object returnObj = null; try { Class classType = Class.forName(className); Constructor constructor = classType .getDeclaredConstructor(intArgsClass); constructor.setAccessible(true); returnObj = constructor.newInstance(intArgs); } catch (NoSuchMethodException ex) { // ExceptionHandler.processFatalException(ex); } catch (Exception ex) { // ExceptionHandler.processFatalException(ex); } return returnObj; } }