You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Owen Funkhouser <ja...@dafunks.com> on 2005/08/24 03:39:23 UTC

Beanutils.getArrayProperty throws NoSuchMethodException for valid method

I'm getting an odd problem when executing the Beanutils.getArrayProperty 
  on an attribute that I know exists.  See the example below 
(TestClass.java and TestBean.java).  What am I doing wrong?

,java.lang.NoSuchMethodException: Unknown property 'vTRate1'
         at 
org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.java:1175)
         at 
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:772)
         at 
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
         at 
org.apache.commons.beanutils.BeanUtils.getArrayProperty(BeanUtils.java:450)
         at com.dyn.beantest.TestClass.print(TestClass.java:16)
         at com.dyn.beantest.TestClass.main(TestClass.java:46)


TestClass.java:
package com.dyn.beantest;

import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;

public class TestClass {
    public TestClass() {
    }

    public void print(TestBean theBean) {
       try {
          List exportFields = TestBean.getAttributeList();
          for (int j = 0; j < exportFields.size(); j++) {
             String[] val = BeanUtils.getArrayProperty(
                       theBean, (String) exportFields.get(j));
             if (null != val) {
                for (int k = 0; k < val.length; k++) {
                   String value = null != val[k] ? val[k] : "";
                   System.out.print(value);
                   if ((k + 1) < val.length) {
                      System.out.print(",");
                   }
                }
             }
             if ((j + 1) < exportFields.size()) {
                System.out.print(",");
             }
          }
       } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
       } catch (InvocationTargetException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
       } catch (NoSuchMethodException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
       }
    }

    public static void main(String[] args) {
       TestBean myBean = new TestBean();
       TestClass thisTest = new TestClass();
       thisTest.print(myBean);
    }
}


TestBean.java:
package com.dyn.beantest;

import java.util.LinkedList;
import java.util.List;

public class TestBean {
    private String testName;
    private String vTRate1;
    private String vTRate1Check;

    public TestBean() {
    }

    public TestBean(String testName) {
       this.testName = testName;
    }

    public static List getAttributeList() {
       List attributeList = new LinkedList();
       attributeList.add("testName");
       attributeList.add("vTRate1");
       attributeList.add("vTRate1Check");
       return attributeList;
    }

    public String getTestName() {
       return testName;
    }

    public void setTestName(String testName) {
       this.testName = testName;
    }

    public String getVTRate1() {
       return vTRate1;
    }

    public void setVTRate1(String rate1) {
       vTRate1 = rate1;
    }

    public String getVTRate1Check() {
       return vTRate1Check;
    }

    public void setVTRate1Check(String rate1Check) {
       vTRate1Check = rate1Check;
    }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org