Ich verwende PropertyUtils.setSimpleProperty, um meine Setter-Methode dynamisch aufzurufen, aber aus irgendeinem Grund bleibe ich eingeschaltet Fehler bekommen. Brauchen Sie Ihre Hilfe, um die Ursache herauszufinden. Hier ist mein Code:Abrufen von java.lang.NoSuchMethodException: Eigenschaft 'xx' hat keine Setter-Methode in Klasse 'Klasse xx' bei Verwendung der Funktion PropertyUtils.setSimpleProperty
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://");
}
}
Beide Methoden werfen Ausnahme
-
Verursacht durch: java.lang.NoSuchMethodException: Anwesen 'REPORT' hat keine Setter-Methode in der Klasse ‚Klasse FileDt 'bei org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty (PropertyUtilsBean.java:2096)
-
Verursacht durch: java.lang.NoSuchMethodException: Anwesen 'report' hat keine Setter-Methode in der Klasse 'Klasse FileDt' bei org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty (PropertyUtilsBean.java:2096)
Hatte die Antwort, die ich zur Verfügung gestellt habe dein Problem lösen? –