NoSuchMethodException while using JAVA Reflection

Posted by Appps on Stack Overflow See other posts from Stack Overflow or by Appps
Published on 2010-05-05T09:57:49Z Indexed on 2010/05/05 10:18 UTC
Read the original article Hit count: 239

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 );
        }

© Stack Overflow or respective owner

Related posts about java

Related posts about reflection