我是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)
最佳答案
您错过了 jar 文件“org-apache-commons-logging.jar”。将此 jar 加载到您的项目中。该问题将得到解决。
关于java - NoClassDefFoundError:org/apache/commons/logging/LogFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25376089/