public class ReflectBeanUtils {
public static void main(String[] args) {
Dog dog=new Dog();
try {
BeanUtils.setProperty(dog, "name", "阿忠");
Object o=BeanUtils.getProperty(dog, "name");
System.out.println(o.toString());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
报错:说是我的javaBean中没有setName方法: 但是我的却是有的。
java.lang.reflect.InvocationTargetException: Cannot set name
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1013)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:454)
at cn.reflect.ReflectBeanUtils.main(ReflectBeanUtils.java:15)
Caused by: java.lang.NoSuchMethodException: Property 'name' has no setter method in class 'class cn.reflect.Dog'
|