本帖最后由 刘源 于 2012-8-14 17:04 编辑
import org.apache.commons.beanutils.BeanUtils;
“问题已经解决”。
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方法,但我有啊。 |