无法在春季生成碧玉报告

时间:2019-11-10 12:23:22

标签: spring-boot nullpointerexception jasper-reports

我正在尝试使用JasperReports生成PDF文件,但是无论我如何尝试,它都给了我NullPointerException。

https://community.jaspersoft.com/questions/520803/getting-null-pointer-exception-fillreport

试图看那里,并更改了jasper属性文件,但是它什么也没做,而且我仍然遇到相同的错误。

尝试了绝对路径,相对路径,将资源作为流获取,什么都没有

这是我用来生成报告的代码

public String generateInvoiceFor (Reservation reservation) throws JRException {

        JasperReport jasperReport = JasperCompileManager.compileReport("I:\\anoranzaHopefullyFinal\\src\\main\\resources\\jasper\\FacturaFinalFinal.jrxml");

        List<Reservation> reservations = reservationService.getAll();

        JRBeanCollectionDataSource jrBeanCollectionDataSource = new JRBeanCollectionDataSource(reservations);

        Map<String,Object> parameters = new HashMap<>();

        parameters.put("Idparam", reservation.getId());

        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, jrBeanCollectionDataSource);

        JasperExportManager.exportReportToPdfFile(jasperPrint, "jasper/jasperOutput/Factura.pdf");

        return "Report successfully generated @path= jasper/jasperOutput/";



    }

1 个答案:

答案 0 :(得分:0)

检查数据源和jasperPrint。如果没有问题,请尝试此操作。

JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(
  new SimpleOutputStreamExporterOutput("PDF NAME IS HERE.pdf"));

SimplePdfReportConfiguration reportConfig
  = new SimplePdfReportConfiguration();
reportConfig.setSizePageToContent(true);
reportConfig.setForceLineBreakPolicy(false);

SimplePdfExporterConfiguration exportConfig
   = new SimplePdfExporterConfiguration();
exportConfig.setMetadataAuthor("Auth name is here");
exportConfig.setEncrypted(true);
exportConfig.setAllowedPermissionsHint("PRINTING");

exporter.setConfiguration(reportConfig);
exporter.setConfiguration(exportConfig);

exporter.exportReport();