本帖最后由 黎志文 于 2013-7-20 15:35 编辑
- package cn.itcast.day3;
- import org.apache.commons.beanutils.BeanUtils;
- class Student
- {
- private int age;
- Student(int age)
- {
- this.age = age;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- }
- //使用BeanUtils工具类对上述Student类中的age属性值进行设置
- class BeanUtilsDemo {
- public static void main(String[] args) throws Exception {
- Student stu = new Student(22);
- BeanUtils.setProperty(stu,"age",30);
- }
- }
复制代码 程序运行后,总是提示:Exception in thread "main" java.lang.reflect.InvocationTargetException: Cannot set age
Caused by: java.lang.NoSuchMethodException: Property 'age' has no setter method in class 'class cn.itcast.day3.Student'
Student类中不是已经有了getter和setter方法么,为何这里总提示说没有setter方法?
|
|