Hi, I am very new to the beanutils. I am trying to set value to an array list using indexed properties.
It is throwing the following error Exception in thread "main" java.lang. IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:572) at java.util.ArrayList.set(ArrayList.java:365) at org.apache.commons.beanutils.PropertyUtilsBean.setIndexedProperty(PropertyUtilsBean.java:1711) Here is my code import java.util.ArrayList; import java.util.List; public class Employee { private String name; private int id; private String dept; private List<Address> addr=new ArrayList<Address>(); public List<Address> getAddr() { return addr; } public void setAddr(List<Address> addr) { this.addr = addr; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getDept() { return dept; } public void setDept(String dept) { this.dept = dept; } } public class Address { private String line; private String aptno; public String getLine() { return line; } public void setLine(String line) { this.line = line; } public String getAptno() { return aptno; } public void setAptno(String aptno) { this.aptno = aptno; } } public void indexdPropTest(){ Employee emp=new Employee(); Address addr=new Address(); try { PropertyUtils.setSimpleProperty(addr, "line","36777" ); PropertyUtils.setIndexedProperty(emp,"addr",0,addr); } 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(); } } Can somebody advise me if anything wrong with this? I had tried replacing arraylist with an array and it was successful. Thanks, D