异常:java.lang.NoSuchMethodError:com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending(Z)V
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19276597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
exception: java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending(Z)V
提问by Andrew Valevskiy
guys! For long time I can't fix the exception: java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending(Z)V
伙计们!很长一段时间我无法修复异常:java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending(Z)V
I've add all need jars into classpath:
我已将所有需要的 jars 添加到类路径中:
- commons-beanutils-1.8.0
- commons-collections-2.1.1
- commons-digester-2.1.0
- commons-javaflow-20060411
- commons-logging-1.1.1
- itext - 2.1.5
- jasperreports - 5.1.0
- commons-beanutils-1.8.0
- commons-collections-2.1.1
- commons-digester-2.1.0
- 公共-javaflow-20060411
- commons-logging-1.1.1
- 文本 - 2.1.5
- 碧玉报告 - 5.1.0
I saw requirements for JasperReports here, so I've all need libraries, but, anyway, I can't fix the bug
我在这里看到了 JasperReports 的需求,所以我都需要库,但是,无论如何,我无法修复错误
My code:
我的代码:
class ForIReport {
public static void main(String[] args) {
// def conn = Sql.newInstance(
// "jdbc:sqlserver://localhost:1433;databaseName=twitter",
// 'sa',
// 'sunrise123',
// 'com.microsoft.sqlserver.jdbc.SQLServerDriver')
// Class.forName("com.microsoft.jdbc.SQLServerDriver").newInstance();
// Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433", 'sa', 'sunrise123');
def fileName = "C:/Users/avalev/Documents/iReport/First.jasper"
def outFileName = "First.pdf"
HashMap hm = new HashMap()
JasperPrint print = JasperFillManager.fillReport(fileName, hm, new JREmptyDataSource())
JRExporter exporter = new JRPdfExporter()
exporter.setParameter(
JRExporterParameter.OUTPUT_FILE_NAME,
outFileName);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print)
exporter.exportReport()
println("Created file :" + outFileName)
}
}
and description of exception
和异常描述
log4j:WARN No appenders could be found for logger (net.sf.jasperreports.extensions.ExtensionsEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending(Z)V
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:596)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:419)
at net.sf.jasperreports.engine.JRExporter$exportReport.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at ForIReport.main(One.groovy:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
I can create the instance of PdfWriter class (for check myself)
我可以创建 PdfWriter 类的实例(用于检查自己)
Thank you for your help
感谢您的帮助
采纳答案by M. Abbas
jasperreports-5.1.0
needs itext-2.1.7
.
jasperreports-5.1.0
需要itext-2.1.7
。
You can see it in the pomof the jasperreports-5.1.0
project:
可以在项目的pom中看到jasperreports-5.1.0
:
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7.js2</version>
<scope>compile</scope>
</dependency>
You need to upgrade the version of itext to version 2.1.7minimum.
您需要将 itext 的版本升级到最低版本2.1.7。
回答by Eugene
I had the same [runtime] error
. What I realized was, I had the wrong jars for the "batik" library. I got all version 1.7 jars from the org.apache.xmlgraphics
. I'm using jasper in this way:
我有同样的[runtime] error
。我意识到的是,我为“蜡染”图书馆准备了错误的罐子。我从org.apache.xmlgraphics
. 我以这种方式使用碧玉:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.0.0</version>
</dependency>
The batik, for example:
蜡染,例如:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-anim</artifactId>
<version>1.7</version>
</dependency>
Also, I made sure I only had one instance of iText in the pom:
另外,我确保在 pom 中只有一个 iText 实例:
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>iText</artifactId>
<version>2.1.7</version>
</dependency>
Hope that helps.
希望有帮助。
回答by Kandy
I had the same issue, when retrieving data from grid and writing to a PDF using
我遇到了同样的问题,当从网格中检索数据并使用
flying-saucer-pdf
飞碟-pdf
The isuue was com.lowagie (itext)and org.xhtmlrenderer (flying-saucer-pdf)versions incompatible,
isuue 是com.lowagie (itext)和org.xhtmlrenderer (flying-saucer-pdf)版本不兼容,
use following,
使用以下,
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf</artifactId>
<version>9.0.7</version>
</dependency>
回答by Sanketik Gote
I have also came across same situation but finally succeeded to resolve it.
我也遇到过同样的情况,但最终成功解决了它。
If you are using maven then add below dependency
如果您使用的是 maven,请添加以下依赖项
<dependency>
<groupId>org.eclipse.birt.runtime.3_7_1</groupId>
<artifactId>com.lowagie.text</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt.runtime.3_7_1</groupId>
<artifactId>com.lowagie.text</artifactId>
<version>2.1.7</version>
</dependency>
or download jar from below link and add to your buildpath
或从下面的链接下载 jar 并添加到您的构建路径
It will be of no use to add itext-2.1.7.jar , Also the latest version of that is itextpdf-5.5.9.jar
添加 itext-2.1.7.jar 也没有用,而且最新版本是 itextpdf-5.5.9.jar