user2782001
user2782001

Reputation: 3498

Groovy JasperReport Missing method exception with the possible solution being listed as the method I call

So, the method exists. It tells me the method exists. But when I call the method with the argument it wants, I get an error..

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)

I'm missing something easy, surely

 //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)
 )

Upvotes: 1

Views: 353

Answers (1)

If you look carefully, you'll see static in the signature provided in the error message; the suggested solution is a non-static method that requires an instance as a receiver. Using @TypeChecked or @CompileStatic when practical will help prevent errors like this.

In this specific instance, JasperExportManager has some static and some non-static versions of its methods. The fix is to change

   JasperExportManager.exportToPdf(report)

to

   JasperExportManager.exportReportToPdf(report)

Upvotes: 1

Related Questions