NoSuchMethodException while using JAVA Reflection
- by Appps
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.
com.test.Test.setAddress1(java.lang.Double) .But I've this method defined in my Class. Is the problem with my code. Can someone please help me? Thanks in advance. I've my code below.
Class[] doubleArrayParamTypes = new Class[ 1 ];
doubleArrayParamTypes[ 0 ] = Double.class;
Class class=Class.forName( "com.test.Test");
Object voObject = class.newInstance();
String data="TestData";
performMapping(class,"setAddress1",doubleArrayParamTypes ,voObject,data);
/* Reflection to set the data */
private void performMapping(Class class,String methodName,Class[] clazz,Object voObject,Object data)
{
class.getMethod( "set" + methodName, clazz ).invoke( voObject, data );
}