本帖最后由 doyxy 于 2014-4-14 09:43 编辑
请教为什么我获取属性总是提示错误呢?Exception in thread "main" java.lang.NoSuchMethodException: Property 'age' has no getter method in class 'class Person'
- import org.apache.commons.beanutils.BeanUtils;
- public class BeanUtilsDemo {
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- Person p = new Person("zs",20);
- BeanUtils.getProperty(p, "age");
- System.out.println(p);
- }
- }
- class Person {
- private String name;
- private int age;
- public Person(String string, int i) {
- // TODO Auto-generated constructor stub
- this.name = string;
- this.age = i;
- }
- 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;
- }
- @Override
- public String toString() {
- return "Person [name=" + name + ", age=" + age + "]";
- }
- }
复制代码
|