I want to create report with Jasper on JavaFX
. I export data from MySql
into the Jasper Report and everything work correct. I import library Jasper Reports 6.2.0 to my project library on Netbeans 8.2
. When i want to create method (in my case showReport()
) to open Jasper File when one button is clicked, it show me error cnnot find symbol on compileReport()
method and fillReport()`method.
here is also the picture of code!! enter image description here ?
code is here:
public void showReport(){
try{
JasperReport jasperReport = new JasperCompileManager.compileReport(" C:\\Users\\PC\\Desktop\\fxmlTest\\src\\fxmltest\\newReport.jasper");
JasperPrint jasperPrint = new JasperFillManager.fillReport(jasperReport,null,connection);
JRViewer viewer = new JRViewer(jasperPrint);
viewer.setOpaque(true);
viewer.setVisible(true);
this.add(viewer);
this.setSize(900,500);
this.setVisible(true);
}catch(Exception e){
System.out.println( e.getMessage());
}
};
JasperCompileManager.compileReport
and JasperFillManager.fillReport
are static
methods.
The syntax you're using on the right hand sides of the assignments
new JasperCompileManager.compileReport(" C:\\Users\\PC\\Desktop\\fxmlTest\\src\\fxmltest\\newReport.jasper")
new JasperFillManager.fillReport(jasperReport,null,connection)
tells the compiler to invoke the constructors of the static
inner class compileReport
in JasperCompileManager
and fillReport
in JasperFillManager
respectively. (Or alternatively the constructors of the classes fillReport
in the JasperCompileManager
package and fillReport
in the JasperFillManager
package.) However those classes don't exist which is why you get the compile time error. You need to remove those new
keywords:
JasperReport jasperReport = JasperCompileManager.compileReport(" C:\\Users\\PC\\Desktop\\fxmlTest\\src\\fxmltest\\newReport.jasper");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null,connection);