I believe D. Rodrigues had actually given you the right solution, I have been researching on a similar problem during the past three days with no luck, and finally have it fixed with the suggestion by D. Rodrigues. I realize this is a post a year ago, I'm posting this because I hope it can be helpful to someone encounter similar question in the future.
My situation is: I have a JasperReport that contain multiple layers of subreports, I would like to run it in a Java application built in Netbeans. Initially, I used getResources() for my main report, when I run it, it works fine in the IDE, but when I build it and run from the jar, it gives a "file not found exception", I tried the alternative of using "Inputstream", and use the subreport as a inputsteam, it always gives "error loading input steam", I was frustrated after days of researching, and it worked with this one.
so the idea is you need to get the main report
JasperReport main = (JasperReport)JRLoader.loadObject(this.getClass().getResource("main.jasper"));
and ALL subreports as resources
JasperReport sub1 = (JasperReport)JRLoader.loadObject(this.getClass().getResource("sub1.jasper"));
JasperReport sub2 = (JasperReport)JRLoader.loadObject(this.getClass().getResource("sub2.jasper"));
JasperReport sub3 = (JasperReport)JRLoader.loadObject(this.getClass().getResource("sub3.jasper"));
JasperReport sub4 = (JasperReport)JRLoader.loadObject(this.getClass().getResource("sub4.jasper"));
(there are 4 subreports in the above example)
Since you are passing subreports as "parameters", so you need to have these parameters in your reports, and you need to make sure these parameters reach the layer where they are used, for mine, the layers are
Main
Sub1
Sub2
Sub3, Sub4
So on my main, I have parameters: sub1, sub2, sub3, sub4, set them all as "Object" in parameter class, set subrepot expression to "$P{sub1}", which will call subreport "Sub1" when run, and in subreport parameters add $P{sub2}, $P{sub3}, $P{sub3}, becasue you are using this parameters in subreports but on Java code, you are only may values to the main report
And so on so forth for the layers after that, my finaly code in Java is:
JasperReport jr = (JasperReport)JRLoader.loadObject(this.getClass().getResource("main.jasper"));
JasperReport sub1 = (JasperReport)JRLoader.loadObject(this.getClass().getResource("sub1.jasper"));
JasperReport sub2 = (JasperReport)JRLoader.loadObject(this.getClass().getResource("sub2.jasper"));
JasperReport sub3 = (JasperReport)JRLoader.loadObject(this.getClass().getResource("sub3.jasper"));
JasperReport sub4 = (JasperReport)JRLoader.loadObject(this.getClass().getResource("sub4.jasper"));
Map para = new HashMap();
para.put("Sub1", sub1);
para.put("Sub2", sub2);
para.put("Sub3", sub3);
para.put("Sub4", sub4);
JasperPrint jp = JasperFillManager.fillReport(jr, para, conn);
JasperViewer.viewReport(jp, false);
and it works like magic!
If it's still not working, please comment or send me email at: smilelrnr@hotmail.com
I'd love to see what I can do!