简体   繁体   中英

How to run JasperReports's report with subreport in java code. Not found subreport

I followed this code example, when i made some report with sub report using iReport v2.0.4

Now i want to run by Java this reports. My code is:

 String rs="E:\\Myproject\\NetBeansProjects\\Inventory_control_system_for_hotel\\
          Mainreportname.jrxml";

 JasperReport jasperMasterReport = JasperCompileManager.compileReport(rs);

 Map<String, Object> parameters = new HashMap<String, Object>();
 parameters.put("para_custId", "66778999");     

 JasperPrint jasperPrint=JasperFillManager.fillReport(jasperMasterReport, parameters, JDBC41.con());

 JasperViewer.viewReport(jasperPrint, false);

Give following error

    net.sf.jasperreports.engine.JRException: Could not load object from     location\Invoice_ireport_subreport2.jasper
  at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:266)
  at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:308)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:257)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:426)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1380)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:692)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:891)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:795)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)
at inventory_control_system_for_hotel.newquery.main(newquery.java:77)

Now I am change my Ireport version 5.5 Some thing like this error

`java.lang.NullPointerException
at net.sf.jasperreports.engine.JRPropertiesMap.readObject(JRPropertiesMap.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)` 

Save my report Path=E:\\Myproject\\NetBeansProjects\\Inventory_control_system_for_hotel\\Mainreportname.jrxml Sub repoth=E:\\Myproject\\NetBeansProjects\\Inventory_control_system_for_hotel\\Subreportname.jrxml Like this

When you link the report and subreport in ireport, you have to set the property "subreport expresion" that is a path relative to your classpath where your subreport is.

Subreport expresion = "reports/Invoice_ireport_subreport2.jasper.jasper"

and you have in your project something like:

src/main/resources/reports/Invoice_ireport_subreport2.jasper.jasper

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM