无法在春季生成碧玉报告

问题描述 投票:-1回答:1

我正在尝试使用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/";



    }
spring-boot nullpointerexception jasper-reports
1个回答
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();
© www.soinside.com 2019 - 2024. All rights reserved.