How to Handle Jasper Report’s NoSuchMethodException

I was generating an ordinary report, when suddenly i met a weird error. My Exception showed a net.sf.jasperreports.engine.JRException and a java.lang.NoSuchMethodException: Unknown property '' when im using Jasper Report’s JRBeanCollectionDataSource. I tought it was because my java bean is not Serializable, but changing my bean to Serializable still didnt fix my errors.
Here is my complete stacktrace

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : 
        at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)
        at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)
        at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100)
        at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:818)
        at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:782)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1433)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:108)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:908)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:830)
        at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:85)
        at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)

Caused by: java.lang.NoSuchMethodException: Unknown property ''
        at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1122)
        at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686)
        at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)

Here is my source code snippet, take a look at line 12, that is where my exception happen.

  @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {     

        List<Log> logs = logService.select();

        FileInputStream fis = new FileInputStream("/ejournal.jasper");
        BufferedInputStream bufferedInputStream = new BufferedInputStream(fis);

        Map<String, String> map = new HashMap<String, String>();
        JRBeanCollectionDataSource jrbcds = new JRBeanCollectionDataSource(logs);

        JasperReport jasperReport = (JasperReport) JRLoader.loadObject(bufferedInputStream);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, jrbcds);
    }

Well actually it’s very easy to fix it, you should either

  • Remove the empty field descriptions from the JRXML.
  • Set the field descriptions to match the bean property names.
  • Pass false as isUseFieldDescription when creating the bean data source, e.g. new JRBeanCollectionDataSource(data, false).

This is how i fixed it,

 @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {     

        List<Log> logs = logService.select();

        FileInputStream fis = new FileInputStream("/ejournal.jasper");
        BufferedInputStream bufferedInputStream = new BufferedInputStream(fis);

        Map<String, String> map = new HashMap<String, String>();
        JRBeanCollectionDataSource jrbcds = new JRBeanCollectionDataSource(logs,false);

        JasperReport jasperReport = (JasperReport) JRLoader.loadObject(bufferedInputStream);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, jrbcds);
    }

I hope it can help others, because i spend some ridicoulously amount of time looking for this workaround.
;-)

Google+

5 Comments

trabelsi

about 4 years ago

yes !!!! i am very happy thx thx thx sir

Reply

edwin

about 4 years ago

Hi trabelsi, glad it could help :)

Budi Oktaviyan

about 3 years ago

Thx bro. barusan nemu yang seperti ini errornya :))

Reply

edwin

about 3 years ago

ya elah si pepe akwkakwk....

Divya

about 2 years ago

Thankyou so much..really helpfull.

Reply

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked


:-[ (B) (^) (P) (@) (O) (D) :-S ;-( (C) (&) :-$ (E) (~) (K) (I) (L) (8) :-O (T) (G) (F) :-( (H) :-) (*) :-D (N) (Y) :-P (U) (W) ;-)