本帖最后由 谢波 于 2013-2-21 13:06 编辑
- package mypackage;
- import java.lang.reflect.InvocationTargetException;
- import java.util.Map;
- import org.apache.commons.beanutils.BeanUtils;
- import org.apache.commons.beanutils.PropertyUtils;
- public class BeanUtilsDemo {
- public static void main(String[] args) throws Exception, InvocationTargetException, NoSuchMethodException
- {
- Demo d = new Demo(5,2);
- String name = "x";
- String value = BeanUtils.getProperty(d, name);
- System.out.println(value);
- }
- }
- class Demo
- {
- private int x, y;
- public Demo(int x, int y) {
- super();
- this.x = x;
- this.y = y;
- }
- public int getX() {
- return x;
- }
- public void setX(int x) {
- this.x = x;
- }
- public int getY() {
- return y;
- }
- public void setY(int y) {
- this.y = y;
- }
- }
复制代码 编译时没问题,运行就会出现异常:
Exception in thread "main" java.lang.NoSuchMethodException: Property 'x' has no getter method in class 'class mypackage.Demo'
我明明有get方法啊 ,,求解? |
|