guys!對於很長一段時間我不能修復異常:java.lang.NoSuchMethodError:com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending(Z)V異常:java.lang.NoSuchMethodError:com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending(Z)V
我已經添加所有需要罐子到類路徑:
- 公地的BeanUtils-1.8.0
- 公地集合-2.1.1
- 公共沼氣池-2.1.0
- 公地javaflow-20060411
- 共享記錄-1.1.1
- iText的 - 2.1.5
- JasperReports的 - 5.1.0
我看到了JasperReports的here要求,所以我一直都需要的庫,但是,無論如何,我不能修復的bug
我的代碼:
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)
}
}
和異常的描述
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)
我可以創建PdfWriter類的實例(檢查自己)
謝謝您的幫助
請檢查您的版本; 'NoSuchMethodError'通常意味着它們不同步(JVM找到類,但類看起來不同於預期)。 – chrylis
@AndrewValevskiy您可以隨時查看您的* JR *庫的pom.xml以獲取所有正確的依賴關係 –