我正在尝试将JasperReports jrxml模板加载到我的DynamicReport对象,但是我在不知道它来自何处的情况下得到了空指针。

该代码实际上是这样的:

DynamicReport dr = new DynamicReport();
DynamicReportBuilder drb = new DynamicReportBuilder();
......
drb.setTemplateFile("styles/myreport.jrxml");
dr = drb.build();


然后我打电话

 JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), resultSetDataSource);


错误是这样的:

java.lang.NullPointerException
at ar.com.fdvs.dj.core.DynamicJasperHelper.generateJasperDesign(DynamicJasperHelper.java:200)
at ar.com.fdvs.dj.core.DynamicJasperHelper.generateJasperReport(DynamicJasperHelper.java:535)
at ar.com.fdvs.dj.core.DynamicJasperHelper.generateJasperReport(DynamicJasperHelper.java:518)
at ar.com.fdvs.dj.core.DynamicJasperHelper.generateJasperPrint(DynamicJasperHelper.java:283)
at ar.com.fdvs.dj.core.DynamicJasperHelper.generateJasperPrint(DynamicJasperHelper.java:236)


有人知道吗?

ps:我在DynamicJasper 3.1.8中使用iReport 5(甚至尝试使用4)。

最佳答案

DynamicJasper和JasperReport需要彼此兼容,我认为这是您的问题。

请找到以下兼容性:

DJ 5.x works with JasperReposrts 4.6+ (and 5.0+, 5.1+ and 5.2) and needs JDK 1.6
DJ 4.x workrs with JasperReports 4.1 to 4.5.x
DJ 3.0.5 works with JR 3.5 up to 4.0


注意:确保您的jrxml是用Jasper版本编译的。

10-07 13:49