>)"函数在 Java 中不起作用-6ren"> >)"函数在 Java 中不起作用-我使用的是 Java 8,动态报告版本是 6.0.0。在 pom.xml 中,我添加了此依赖项: net.sourceforge.dynamicreports dynamicrepo-6ren">
gpt4 book ai didi

java - 动态报告 - ".toPdf(<>)"函数在 Java 中不起作用

转载 作者:行者123 更新时间:2023-12-02 09:15:09 27 4
gpt4 key购买 nike

我使用的是 Java 8,动态报告版本是 6.0.0。在 pom.xml 中,我添加了此依赖项:

<dependency>
<groupId>net.sourceforge.dynamicreports</groupId>
<artifactId>dynamicreports-core</artifactId>
<version>6.0.0</version>
</dependency>

此代码用于生成报告参数:

JasperReportBuilder report = new JasperReportBuilder();
report.setPageMargin(DynamicReports.margin().setLeft(30).setRight(30).setTop(10).setBottom(10));
report.setPageFormat(PageType.A4, PageOrientation.PORTRAIT);
report.title(cmp.subreport(subReport1));

这里,变量subreport1包含所有报告数据。经验证,它们是正确的。

生成所有报告数据后,这是我执行的将报告详细信息写入文件的代码:

FileOutputStream st = new FileOutputStream("<<DUMMY_FILE_PATH>>");
report.toPdf(st);

在存在 .toPdf 的这一行,抛出以下异常:

Exception in thread "main" java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.<init>(SimpleFontExtensionHelper.java:149)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.getInstance(SimpleFontExtensionHelper.java:131)
at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.ensureFontExtensions(FontExtensionsRegistry.java:80)
at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:57)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:130)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.getExtensions(DefaultJasperReportsContext.java:277)
at net.sf.jasperreports.engine.fonts.FontUtil.getFontInfo(FontUtil.java:191)
at net.sf.jasperreports.engine.fonts.FontUtil.getFontInfo(FontUtil.java:291)
at net.sf.jasperreports.engine.fonts.FontUtil.getAwtFontFromBundles(FontUtil.java:476)
at net.sf.jasperreports.engine.fonts.FontUtil.getAwtFontFromBundles(FontUtil.java:466)
at net.sf.dynamicreports.design.transformation.StyleResolver.getFont(StyleResolver.java:122)
at net.sf.dynamicreports.design.transformation.StyleResolver.getFont(StyleResolver.java:100)
at net.sf.dynamicreports.design.transformation.StyleResolver.getFontHeight(StyleResolver.java:69)
at net.sf.dynamicreports.design.transformation.TemplateTransform.getTextFieldHeight(TemplateTransform.java:1391)
at net.sf.dynamicreports.design.transformation.ComponentTransform.textField(ComponentTransform.java:395)
at net.sf.dynamicreports.design.transformation.ComponentTransform.component(ComponentTransform.java:155)
at net.sf.dynamicreports.design.transformation.ComponentTransform.list(ComponentTransform.java:303)
at net.sf.dynamicreports.design.transformation.BandTransform.band(BandTransform.java:231)
at net.sf.dynamicreports.design.transformation.BandTransform.transform(BandTransform.java:86)
at net.sf.dynamicreports.design.base.DRDesignReport.transform(DRDesignReport.java:155)
at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:127)
at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:111)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperReportDesign(JasperReportBuilder.java:299)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.getJasperParameters(JasperReportBuilder.java:346)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperPrint(JasperReportBuilder.java:363)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.export(JasperReportBuilder.java:896)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toPdf(JasperReportBuilder.java:735)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toPdf(JasperReportBuilder.java:724)

请让我知道此错误的解决方案。

最佳答案

我找到了实际的解决方案。 xerces jar 和动态报告 jar 之间存在版本不匹配。通过添加以下依赖项解决了这个问题:

<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>

关于java - 动态报告 - ".toPdf(<<filepath>>)"函数在 Java 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59051262/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com