public static Object createObject ( Class classObject , Object [ ] params ) throws Exception { Constructor [ ] constructors = classObject . getConstructors ( ) ; Object object = null ; for ( int counter = 0 ; counter < constructors . length ; counter ++ ) { try { object = constructors [ counter ] . newInstance ( params ) ; } catch ( Exception e ) { if ( e instanceof InvocationTargetException ) ( ( InvocationTargetException ) e ) . getTargetException ( ) . printStackTrace ( ) ; // do nothing, try the next constructor } } if ( object == null ) throw new InstantiationException ( ) ; return object ; }
Instantaite an Object instance requires a constractor with parameters