本帖最后由 李挺 于 2013-2-17 14:51 编辑
- import org.apache.commons.beanutils.BeanUtils;
- public class PropertyDescriptorDemo {
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception{
- // TODO Auto-generated method stub
- ReflectPoint rf=new ReflectPoint(3, 5);
-
- System.out.println(BeanUtils.getProperty(rf, "x"));
- }
- }
- class ReflectPoint //这是个javabean
- {
- private int x;
- private int y;
- public ReflectPoint(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;
- }
- @Override
- public String toString() {
- return "ReflectPoint [x=" + x + ", y=" + y + "]";
- }
-
- }
复制代码 这里会报错
Exception in thread "main" java.lang.NoSuchMethodException: Property 'x' has no getter method in class 'class day2.ReflectPoint'
可是我有getX()方法啊 |
|