0

这是我打印发票页的源线。我的报告不在 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);
}
4

1 回答 1

2

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

于 2013-10-02T18:18:58.890 回答