Java Groovy JasperReport缺少方法异常,可能的解决方案列为我调用的方法
因此,该方法是存在的。它告诉我这个方法是存在的。但是当我用它想要的参数调用这个方法时,我得到了一个错误Java Groovy JasperReport缺少方法异常,可能的解决方案列为我调用的方法,java,groovy,Java,Groovy,因此,该方法是存在的。它告诉我这个方法是存在的。但是当我用它想要的参数调用这个方法时,我得到了一个错误 groovy.lang.MissingMethodException: No signature of method: static net.sf.jasperreports.engine.JasperExportManager.exportToPdf() is applicable for argument types: (net.sf.jasperreports.engine.Jasp
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)
)
如果仔细查看,您将在错误消息中提供的签名中看到
静态
;建议的解决方案是一种非静态方法,它需要一个实例作为接收器。在实际情况下使用@TypeChecked
或@CompileStatic
将有助于防止此类错误
在这个特定的实例中,jaspeexportmanager
有其方法的一些静态和一些非静态版本。解决办法是改变
JasperExportManager.exportToPdf(report)
到
您错过了
静态
。显然,您没有将方法调用与适当的instance.bingo关联。exportToPdf不是静态的,exportReportToPDf是静态的。长时间盯着屏幕看。如果能适当充实,这不是一个坏问题,如果你能包含导致此错误的代码片段,我很乐意写出一个正确的答案。
JasperExportManager.exportReportToPdf(report)