The World’s Largest Online Community for Developers

'; java - Jasper sub report error - LavOzs.Com
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Caused by: net.sf.jasperreports.engine.JRException: Resource not found at : nullinvoiceDetail.jasper
    at net.sf.jasperreports.repo.RepositoryUtil.getResource(
    at net.sf.jasperreports.repo.RepositoryUtil.getReport(
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(
    ... 81 more
JasperReport jasperReport = JasperCompileManager.compileReport(hdnWebInfPath+seperator+"reports"+seperator+"invoice.jrxml");
                        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, model, new JREmptyDataSource());
                        JasperExportManager.exportReportToPdfFile(jasperPrint, fPath+seperator+fileName);

this works when simple report not working for sub reports...

My Jarper knowledge is couple versions old, but lets hope this is helpful.

This is because jasper does not find your subreport. Jasper can compile your report, but it does not compile referenced subreports when you call compileReport. When filling the report referenced subreports are not found because they are not available in working directory.

(Compiling report every time it is requested is kind a bad idea (unless you have some really heavy reasons to do so).)

There are couple of ways solving this. One would be making sure the the paths are correct and precompiling the reports before application deployment. Links Alex K provided are an excellent source for this. If in application compilation is required then using solution below is possible:

In web application I've found that a working practice is to handle compilation and filling your reports is to manage it manually. Here is helper class I wrote. Hope that it is useful (it uses spring, but those parts are easily replaceable).

public class ReportSource {

    // Key = document name, Value = path to .jrxml
    private Map<String, String> reports;
    private final Map<String, JasperReport> compiled;

    private final boolean lazy;

    private final Logger log = Logger.getLogger(ReportSource.class);

    public ReportSource(final boolean lazyBuild) {
        lazy = lazyBuild;
        compiled = new HashMap<String, JasperReport>();

    public void setCompileTargets(final Map<String, String> targets) {
        reports = new HashMap<String, String>(targets);
        if (!lazy) {
            for (final String key : targets.keySet()) {

    public JasperReport getReport(final String reportName) {
        if (compiled.get(reportName) == null) { // not found or not compiled
  "Lazily compiling: " + reportName);
            return compile(reportName);
        return compiled.get(reportName);

    private JasperReport compile(final String reportName) {
        final String path = reports.get(reportName);

        InputStream fis = null;
        JasperReport report = null;
        try {
            final FileSystemResourceLoader resourceLoader = new FileSystemResourceLoader();
            fis = resourceLoader.getResource(path).getInputStream();
  "Compiling report: " + reportName + " (" + path + ")");
            report = JasperCompileManager.compileReport(fis);
        } catch (final IOException ioe) {
            throw new IllegalStateException("Configuration error file: " + path + " (for key: " + reportName +") not found.", ioe);
        } catch (final JRException jre) {
            throw new IllegalStateException("Configuration error file: " + path + " (for key: " + reportName +") not found.", jre);

        compiled.put(reportName, report);
        return report;

With the help of this class you can refer subreports in documents like this:

    <reportElement x="0" y="0" width="200" height="30"/>
    <subreportParameter name="data">
    <subreportParameter name="REPORT_RESOURCE_BUNDLE">
    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
    <subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{data}.getSubreport("name_of_your_subreport")]]></subreportExpression>

Here $P{data} is suitable object provided as document parameter, where getSubreport() ends up calling ReportSource.getReport(). It could of course be $P{reportSource}.getReport("....") if ReportSource is provided as parameter directly. (We use ReportModel-approach; in short it is presentation model fitted to the context of reports).

JasperReports NoClassDefFoundError exception on net.sf.jasperreports.engine.util.JRStyledTextParser
iReport font not available to JVM net.sf.jasperreports.awt.ignore.missing.font=true has no effect.
Jasper reports: getting errors of class not found
Jasper reports List as Parameter
JasperReport: How to get date from the "oracle.sql.TIMESTAMP' field?
An error has occurred. Please contact your system administrator. (6632) error in Jasper server 6.2
Barcode creation in Jasper report: n is not a valid character for Standard 2 of 5 encoding
Call Jasper subreports in java