javabeans - Getting java.lang.NoSuchMethodException: Property 'xx' has no setter method in class 'class xx' while using PropertyUtils.setSimpleProperty function -




i using propertyutils.setsimpleproperty invoke setter method dynamically, reason keep on getting error. need assistance figure out root cause. here 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

  1. caused by: java.lang.nosuchmethodexception: property 'reportname' has no setter method in class 'class filedt' @ org.apache.commons.beanutils.propertyutilsbean.setsimpleproperty(propertyutilsbean.java:2096)

  2. caused by: java.lang.nosuchmethodexception: property 'reportlocation' has no setter method in class 'class filedt' @ org.apache.commons.beanutils.propertyutilsbean.setsimpleproperty(propertyutilsbean.java:2096)

propertyutilsbean.setsimpleproperty(object bean, string name, object value)) works public methods only. looks class uses package scope (missing public keyword in class definition).

running following example:

import org.apache.commons.beanutils.propertyutils;  import java.lang.reflect.invocationtargetexception;  class filedt {     string reportname;     string reportlocation;      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;     }      public static void main(string[] args) throws illegalaccessexception, nosuchmethodexception, invocationtargetexception {         filedt dt = new filedt();         // #1         propertyutils.setsimpleproperty(dt, "reportname", "abc.html");         // #2         propertyutils.setsimpleproperty(dt, "reportlocation", "c://");     } } 

throws exception have described:

exception in thread "main" java.lang.nosuchmethodexception: property 'reportname' has no setter method in class 'class filedt'     @ org.apache.commons.beanutils.propertyutilsbean.setsimpleproperty(propertyutilsbean.java:2096)     @ org.apache.commons.beanutils.propertyutils.setsimpleproperty(propertyutils.java:928)     @ filedt.main(filedt.java:28) 

making class public solves problem:

import org.apache.commons.beanutils.propertyutils;  import java.lang.reflect.invocationtargetexception;  public class filedt {     string reportname;     string reportlocation;      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;     }      public static void main(string[] args) throws illegalaccessexception, nosuchmethodexception, invocationtargetexception {         filedt dt = new filedt();         // #1         propertyutils.setsimpleproperty(dt, "reportname", "abc.html");         // #2         propertyutils.setsimpleproperty(dt, "reportlocation", "c://");     } } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -