如何在java中修复NoClassDefFoundError [英] how to fix NoClassDefFoundError in java

查看:119
本文介绍了如何在java中修复NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我打印发票页面的源代码。我的报告不在java包中。我将它保存在一个名为report的文件夹中,该文件夹与我的java项目在同一个分区中。现在我有NoClassDefFoundError。

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);
}


推荐答案

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

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)

这篇关于如何在java中修复NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆