如何在java中修复NoClassDefFoundError

时间:2013-10-02 18:14:27

标签: java swing jasper-reports

这是我打印发票页面的源代码。我的报告不在java包中。我将它保存在一个名为“report”的文件夹中,该文件夹与我的java项目在同一个分区中。现在我有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);
}

1 个答案:

答案 0 :(得分:2)

您的编译器在编译时找到必要的库,但您的程序无法在运行时在类路径中找到它们。 将Jasper库添加到类路径中。 (我将有其依赖性......大部分都是apache的公地)