2

I'm new in JasperReports and I want to integrate a JasperReports into my Java program, so when I click print button the program will show the report. But I get a NoClassDefFoundError when I click the button.

Code

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

Runtime error

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)
Alex K
  • 22,315
  • 19
  • 108
  • 236
buncis
  • 2,148
  • 1
  • 23
  • 25
  • 2
    `NoClassDefFoundError: org/apache/commons/logging/LogFactory` Make sure Apache commons logging lib is also on the runtime classpath of the app. – Andrew Thompson Aug 19 '14 at 05:23
  • See also [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) – Andrew Thompson Aug 19 '14 at 05:25
  • I already add all the required library commons-beanutils-1.8.0.jar commons-collections-3.2.1.jar comons-digester-2.1.jar commons-logging-1.1.1.jar groovy-all-2.0.1.jar jdt-compiler-3.1.1.jar joda-time-2.4.jar now i just get this error `net.sf.jasperreports.engine.JRException: Byte data not found at : leaf_banner_gray.png java.lang.NumberFormatException: For input string: ""` Thanks for your help guys – buncis Aug 19 '14 at 05:57
  • possible duplicate of [Passing parameter to jasper report from java without DB](http://stackoverflow.com/questions/7888064/passing-parameter-to-jasper-report-from-java-without-db) – Alex K Aug 19 '14 at 09:16

2 Answers2

5

You have missed the jar file "org-apache-commons-logging.jar". Load this jar into your project. The Issue going to be resolved.

N.L.N.Rao
  • 66
  • 3
  • 3
    thanks btw i need to load another jar too. this is all the jar that I load, `commons-beanutils-1.8.0.jar` `commons-collections-3.2.1.jar` `comons-digester-2.1.jar` `commons-logging-1.1.1.jar` `groovy-all-2.0.1.jar` `jdt-compiler-3.1.1.jar` `joda-time-2.4.jar` – buncis Aug 19 '14 at 06:06
0

Error Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

Solution

missed the jar file "org-apache-commons-logging.jar".

Download https://commons.apache.org/proper/commons-logging/download_logging.cgi

and then add library

Load this jar into your project. The Issue going to be resolved.

user7641341
  • 169
  • 1
  • 5