我是 JasperReports 的新手,我想将 JasperReports 集成到我的Java程序中, 所以当我点击打印按钮时,程序将显示报告。但是当我点击按钮时,我得到一个 NoClassDefFoundError 。
JButton btnReport= new JButton("Report");
btnReport.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try{
String fileName= "src/learnReport/Leaf_Grey.jasper";
Connection con = connect.getConnect();
File file = new File(NameFile);
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(file);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null,con);
JasperViewer.viewReport(jasperPrint,false);
} catch(Exception ex){
System.out.println(ex);
}
}
});
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:81)
at learnReport.Learning$6.actionPerformed(Learning.java:195)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
答案 0 :(得分:5)
您错过了jar文件“org-apache-commons-logging.jar”。将此jar加载到您的项目中。问题将得到解决。