0

This is my source cord to print my invoice page. My report is not in java package. I kept it inside a folder called "report" which is in same partition with my java project. now I'm having NoClassDefFoundError.

try {
    String date1 = new SimpleDateFormat("yyyy-MM-dd").format(isdate.getDate());
    String time1 = istime.getValue().toString().split(" ")[3];
    date1 = date1 + " " + time1;

    String date2 = new SimpleDateFormat("yyyy-MM-dd").format(redate.getDate());
    String time2 = retime.getValue().toString().split(" ")[3];
    date2 = date2 + " " + time2;

    JRTableModelDataSource dataSource = new JRTableModelDataSource(jTable1.getModel());
    String reportsource = " D://report/report1.jrxml";
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("inid", txtInvoiceID.getText());
    params.put("cuname", txtCuName.getText());
    params.put("cuadd", txtCuid.getText());
    params.put("cutp", txtTPNo.getText());
    params.put("isdate", date1);
    params.put("redate", date2);
    params.put("advance", txtAdvance.getText());
    params.put("due", txtDue.getText());
    params.put("total", txtGtotal.getText());
    JasperReport jasperReport = JasperCompileManager.compileReport(reportsource);
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
    JasperViewer.viewReport(jasperPrint, false);
    JOptionPane.showMessageDialog(null, "Done");
} catch (Exception e) {
    System.out.println(e);
}
Alex K
  • 22,315
  • 19
  • 108
  • 236
Dilini
  • 69
  • 4
  • 10

1 Answers1

2

Your compiler finds the necessary libraries at compile time, but your program can't find them at runtime in the classpath. Add Jasper library to your classpath. (I will have its dependances.. most of them are apache commons)

Alvaro
  • 11,797
  • 9
  • 40
  • 57
  • But when I'm running that project I'm having "net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: report\report1.jrxml (The system cannot find the path specified)" I put path as String reportsource = " D://report/report1.jrxml"; . Help me – Dilini Oct 03 '13 at 02:05
  • Okay, this means jasper can't find the file... try removing the initial space - change " D://report/report1.jrxml" to "D://report/report1.jrxml" to see if that's the problem.. if not, I'll try it this afternoon! – Alvaro Oct 03 '13 at 09:56