Using subreports in Jasper iReport
When trying to create a subreport in Jasper, I kept receiving the following error:
net.sf.jasperreports.engine.JRException: Could not load object from location
every time I tried to generate a sample PDF file. The subreport has its own SQL statement and needs to select data based on an id number passed as a parameter from the main report, so for the longest time I thought I was passing the parameter wrong.
Turns out that the real problem was in order to make a subreport work it has to be compiled. I had it compiled, but the compiled version of the resport (ending in .jasper) was being saved in a different folder. I didn’t know it was .jasper so I tried to specify every possible path to the .jrxml file which did not work.
So for anyone experiencing this problem, here’s what to do:
- Compile the subreport.
- Find the compiled .jasper file.
- Make sure your main report is referencing this .jasper file and nothing else.