简体   繁体   English

生成JasperReport的报告时出现NoSuchMethodError

[英]NoSuchMethodError while generating JasperReport's report

I'm generating PDF report using JasperReports library. 我正在使用JasperReports库生成PDF报告。 I this report I have a QRCode which makes problem. 我在此报告中有一个QRCode导致了问题。 I had to add many libraries: 我必须添加许多库:

jasperreports, itext, itext-pdfa, itext-pdf, commons-beanutils, commons-collections, commons-digester, commons-logging, groovy-all, barbecue, barcode, barcode4j, batik-anim, batik-bridge, core, w3c.css.sac, w3c,xmlgraphics-commons, batik-all jasperreports,itext,itext-pdfa,itext-pdf,commons-beanutils,commons-collection,commons-digester,commons-logging,groovy-all,烧烤,条形码,barcode4j,蜡染-anim,蜡染桥,核心,w3c。 css.sac,w3c,xmlgraphics-commons,蜡染全部

I receive an exception: 我收到一个例外:

java.lang.ClassCastException: org.apache.batik.anim.dom.SVGOMDocument cannot be cast to org.apache.batik.dom.svg.SVGOMDocument
at org.apache.batik.bridge.BridgeContext.setDocument(Unknown Source)
at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
at net.sf.jasperreports.renderers.AbstractSvgDataToGraphics2DRenderer.ensureSvg(AbstractSvgDataToGraphics2DRenderer.java:166)
at net.sf.jasperreports.renderers.AbstractSvgDataToGraphics2DRenderer.getDimension(AbstractSvgDataToGraphics2DRenderer.java:111)
at net.sf.jasperreports.engine.export.JRPdfExporter$InternalImageProcessor.processGraphics2D(JRPdfExporter.java:1793)
at net.sf.jasperreports.engine.export.JRPdfExporter$InternalImageProcessor.process(JRPdfExporter.java:1582)
at net.sf.jasperreports.engine.export.JRPdfExporter$InternalImageProcessor.access$300(JRPdfExporter.java:1535)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1475)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:1093)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:1056)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:920)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:537)
at reports.JasperReport.generatePdf(JasperReport.java:178)

What is wrong? 怎么了?

If this is your own code (you wrote it), it is just because of you have imported the wrong SVGOMDocument class (which belongs to different Java package). 如果这是您自己的代码(您编写的),那仅仅是因为您导入了错误的SVGOMDocument类(属于不同的Java包)。 You should be able to figured it out quickly with decent Java IDE (Eclipse, IntelliJ, NetBeans). 您应该能够使用不错的Java IDE(Eclipse,IntelliJ,NetBeans)快速解决问题。

Also, as much as possible try to avoid implicit imports such as: 另外,请尽可能避免隐式导入,例如:

import org.apache.batik.dom.svg.*;
import org.apache.batik.anim.dom.*;

That might reduce your code stability, eg lines added above might alter your reference of existing working code. 这可能会降低代码的稳定性,例如,上面添加的行可能会更改对现有工作代码的引用。 Use explicit imports (import org.apache.batik.dom.svg.SVGOMDocument). 使用显式导入(导入org.apache.batik.dom.svg.SVGOMDocument)。

Find out what's the return type of the method you invoke, and import from the correct Java package. 找出您调用的方法的返回类型是什么,然后从正确的Java包中导入。 In Eclipse IDE, you can just remove the import that contains the package/class above, and choose Source > Organize Imports (Ctrl-Shift-O). 在Eclipse IDE中,您仅可以删除包含上述包/类的导入,然后选择“源”>“组织导入”(Ctrl-Shift-O)。

If you have both classes in single source code file, you might need to use full class name for one of the classes, eg: 如果两个类都在单个源代码文件中,则可能需要对其中一个类使用完整的类名,例如:

org.apache.batik.dom.svg.SVGOMDocument document = SomeLibrary.getSomething();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM