I am using PropertyUtils.setSimpleProperty to invoke my setter method dynamically, but for some reason I keep on getting error. Need your assistance to figure out the root cause. Here is my code:
class FileDt {
String reportName=null;
String reportLocation=null;
public String getReportName() {
return reportName;
}
public void setReportName(String reportName) {
this.reportName = reportName;
}
public String getReportLocation() {
return reportLocation;
}
public void setReportLocation(String reportLocation) {
this.reportLocation = reportLocation;
}
}
class Foo {
public static void main (String... args) {
FileDt dt = newFileDt();
// #1
PropertyUtilsBean.setSimpleProperty(dt, "reportName", "abc.html");
// #2
PropertyUtilsBean.setSimpleProperty(dt, "reportLocation", "c://");
}
}
Both of these methods throw exception
Caused by: java.lang.NoSuchMethodException: Property 'reportName' has no setter method in class 'class FileDt' at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2096)
Caused by: java.lang.NoSuchMethodException: Property 'reportLocation' has no setter method in class 'class FileDt' at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2096)