Question

My stack trace looks like this:

java.lang.IllegalArgumentException: Indexed or mapped properties are not supported on objects of type Map: get(1)
at org.apache.commons.beanutils.PropertyUtilsBean.getPropertyOfMapBean(PropertyUtilsBean.java:813)
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:764)
at org.apache.commons.beanutils.BeanUtilsBean.getNestedProperty(BeanUtilsBean.java:715)
at org.apache.commons.beanutils.BeanUtilsBean.getProperty(BeanUtilsBean.java:741)
at org.apache.commons.beanutils.BeanUtils.getProperty(BeanUtils.java:382)

I get it here when I try to access part of a map:

//Property Names
for ( int i=1; i < planMonthList.size(); i++ )
{
  planTab.add("planPosition....get" + "(" + i + ")");
}
Was it helpful?

Solution

You can't iterate over a map directly. You have to iterate over the keySet, the entrySet, or the values collection

Example:

Map <String,Integer> m = new HashMap<String,Integer>();

m.put("A", 1);
m.put("B", 2);
m.put("C", 3);

// Iterate over keys
for (String key : m.keySet()) {
    System.out.println("Key=["+key+"], value=["+m.get(key)+"]");
}

// Iterate over values
for (Integer value : m.values()) {
    System.out.println("Value=["+value+"]");
}

// Iterate over entrySet
for (Map.Entry<String,Integer> entry : m.entrySet()) {
    System.out.println("Key=["+entry.getKey()+"], value=["+entry.getValue()+"]");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top