gpt4 book ai didi

java - Groovy JasperReport 缺少方法异常,可能的解决方案被列为我调用的方法

转载 作者:行者123 更新时间:2023-11-30 06:56:53 25 4
gpt4 key购买 nike

所以,这个方法是存在的。它告诉我该方法存在。但是当我用它想要的参数调用该方法时,我收到错误..

groovy.lang.MissingMethodException:
No signature of method: static net.sf.jasperreports.engine.JasperExportManager.exportToPdf()
is applicable for argument types:

(net.sf.jasperreports.engine.JasperPrint)

values: [net.sf.jasperreports.engine.JasperPrint@1effe1]

Possible solutions: exportToPdf(net.sf.jasperreports.engine.JasperPrint)

我肯定错过了一些简单的事情

 //custom class
def normalized = new NormalizedData(instance);
def json = normalized as JSON;
def fileName = "SLDATA_${instance.id}.pdf";
String reportPath = confHolder.config.jasper.dir.reports + "/main.jasper"

InputStream byteIn = new byteArrayInputStream(json.toString().getBytes())
JsonDataSource reportJSON = new JsonDataSource(byteIn)

JasperPrint report = JasperFillManager.fillReport(reportPath, [:], reportJSON)

FileUtils.writeByteArrayToFile(
new File("${conf.outputDir}/${fileName}"),
JasperExportManager.exportToPdf(report)
)

最佳答案

如果仔细观察,您会在错误消息中提供的签名中看到static;建议的解决方案是一种非静态方法,需要一个实例作为接收器。在实际情况下使用 @TypeChecked@CompileStatic 将有助于防止此类错误。

在此特定实例中,JasperExportManager 的方法有一些静态版本和一些非静态版本。解决办法是改变

   JasperExportManager.exportToPdf(report)

   JasperExportManager.exportReportToPdf(report)

关于java - Groovy JasperReport 缺少方法异常,可能的解决方案被列为我调用的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41627362/

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