Hi I'm trying to use reflection to invoke a method and update the setter value of that method. But I'm getting NoSuchMethodException while ivoking that method. I've updated the code. I'm so sorry for the errors in the previous code. I've refractored the code. The exception occurs when the setMethod of the class accepts primitive type arguments.
private static Object performMapping( Class voClass, Class[] clazz, Object voObject, Object data,String fieldType ){
voClass.getMethod( "set" + fieldType, clazz ).invoke( voObject, data );
return voObject;
}
private static Object mapField(ResultSet rs){
Class voClass=Class.forName( "com.test.Test" );
Object voObject = voClass.newInstance();
Class[] doubleArrayParamTypes = new Class[ 1 ];
doubleArrayParamTypes[ 0 ] = Double.class;
voObject = performMapping( voClass, doubleArrayParamTypes, voObject, rs.getDouble(fieldType.getColumn()), "Mark" );
}
/* This is my Class. I need to set the Mark. But it is primitive double. Is it possible to set the mark using the above code? */
public class Test{
private double mark;
public double getMark() {
return mark;
}
public void setMark(double mark) {
this.mark = mark;