class ReflectPoint{
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;
}
}
public class IntroSpectorTest {
public static void main(String[] args) throws Exception {
ReflectPoint pt1 =new ReflectPoint(3,5);
System.out.println(BeanUtils.getProperty(pt1, "y"));
BeanUtils.setProperty(pt1,"x", "9");
System.out.println(pt1.getX());
}
}
错误提示:
Exception in thread "main" java.lang.NoSuchMethodException: Property 'y' has no getter method
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1127)
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686)
at org.apache.commons.beanutils.BeanUtilsBean.getNestedProperty(BeanUtilsBean.java:698)
at org.apache.commons.beanutils.BeanUtilsBean.getProperty(BeanUtilsBean.java:723)
at org.apache.commons.beanutils.BeanUtils.getProperty(BeanUtils.java:265)
at jichujiaqiang.IntroSpectorTest.main(IntroSpectorTest.java:122)
怎么解决啊。我哪里错了。他说我没有什么getter方法,但我有啊。作者: 周瑞 时间: 2012-8-14 16:58
ReflectPoint这个类楼主你放在单独的class文件设置成public试下,可能BeanUtils.getProperty()这个方法有限制条件有关。
相关文档是这样说的:
The class must be public, and provide a public constructor that accepts no arguments. This allows tools and applications to dynamically create new instances of your bean, without necessarily knowing what Java class name will be used ahead of time.作者: 刘源 时间: 2012-8-14 17:03
万分感谢。搞定了。还有这某个条件啊