package cn.itcast.heima;
import org.apache.commons.beanutils.BeanUtils;
class Sutdent{
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class IntroBean {
public static void main(String[] args)throws Exception {
Sutdent stu=new Sutdent();
BeanUtils.setProperty(stu,"age",2);//提示的错误在这 BeanUtils.getProperty(stu, "age");
}
}
大家帮忙看看,这段代码怎么运行不对啊?工具包都倒好了,运行时会出现这种错误
Cannot set age
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1025)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:313)
at cn.itcast.heima.IntroBean.main(IntroBean.java:26)
Caused by: java.lang.NoSuchMethodException: Property 'age' has no setter method
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1746)
at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1648)
at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677)
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022)
... 2 more
Exception in thread "main" |
|