所以,这个方法是存在的。它告诉我该方法存在。但是当我用它想要的参数调用该方法时,我收到错误..
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/