问题描述
在Struts应用程序属性中获得以下错误的类型为String Array [] ...
private String procBatchCode[] = new String[25];
public void setProcBatchCode(String[] strings) {
procBatchCode = strings;
}
package com.americanexpress.ms3.actionform.rejectedpayables;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections.MultiMap;
public class Test {
public static void main(String args[]){
RejectedPayablesCommonFormTest rj=new RejectedPayablesCommonFormtest();
System.out.println("Calling .....");
Map <String,Object>map=new HashMap<String,Object>() ;
map.put("abc","abc");
map.put("fromDate","FormDate");
String[] batchCodeList={"015"};
String []batchCode={"015"};
map.put("procBatchCode",batchCode);
map.put("procBatchCodeList",batchCodeList);
try {
org.apache.commons.beanutils.BeanUtils.populate(rj,map);
}catch(Exception e){
e.printstacktrace();
}
System.out.println("Calling ..End ..."+rj.getProcBatchCodeList().size()+" batch code list"+rj.getProcBatchCodeList().size());
}
}
...
java.lang.IllegalArgumentException:无法调用com.americanexpress.ms3.actionform.rejectedpayables.RejectedPayablesCommonFormTest.setProcBatchCode-参数类型不匹配 在org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1778) 在org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759) 在org.apache.commons.beanutils.PropertyUtilsBean.setnestedProperty(PropertyUtilsBean.java:1648) 在org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677) 在org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022) 在org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811) 在org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298) 在com.americanexpress.ms3.actionform.rejectedpayables.Test.main(Test.java:28)
解决方法
rj
对象中“ procBatchCode”字段的类型与映射中的键“ procBatchCode”的对象类型不匹配。