日期:2014-05-20  浏览次数:21015 次

求助:java.beans.Expression
public class PropertyBean {
class SimpleBean{
String date = null;

/**
* @return the date
*/
public String getDate() {
return date;
}

/**
* @param date the date to set
*/
public void setDate(String date) {
this.date = date;
}

}

public static void main(String[] args) {
PropertyBean pb = new PropertyBean();
SimpleBean sb = pb.new SimpleBean();
Statement stm = new Statement(sb, "setDate",new Object[]{"123"});
try {
stm.execute();
} catch (Exception e) {
e.printStackTrace();
}

Expression exp = new Expression(sb, "getDate", new Object[0]);
try {
exp.execute();
System.out.println(exp.getValue());
} catch (Exception e) {
e.printStackTrace();
}
}
}

为什么报:
java.lang.NoSuchMethodException: PropertyBean$SimpleBean.setDate("123");
at java.beans.Statement.invoke(Unknown Source)
at java.beans.Statement.execute(Unknown Source)
at com.common.example.beans.PropertyBean.main(PropertyBean.java:31)
java.lang.NoSuchMethodException: <unbound>=PropertyBean$SimpleBean.getDate();
at java.beans.Statement.invoke(Unknown Source)
at java.beans.Statement.execute(Unknown Source)
at com.common.example.beans.PropertyBean.main(PropertyBean.java:38)



------解决方案--------------------
Statement stm = new Statement();
是不是这个构造函数用错了?
------解决方案--------------------
很简单,因为你的SimpleBean不是public的...