0
package javaapplication3;

import java.util.HashMap;
import javax.swing.JOptionPane;


 public class NewJFrame extends javax.swing.JFrame {
 public NewJFrame() {
    initComponents();
}

public void print()
{
    String id="Adm-1";
    String FileName=null;
    HashMap param=new HashMap();
    param.put("id",id);
    FileName="E:\\Reports\\reportNew.jasper";
    try
    {
        ReportViewer viewer=new ReportViewer(FileName,param);
        viewer.setSize(850,500);
        viewer.setVisible(true);
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(this, e);
    }
}
@SuppressWarnings("unchecked")

private void initComponents() {

    jButton1 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(153, 153, 153)
            .addComponent(jButton1)
            .addContainerGap(174, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(65, 65, 65)
            .addComponent(jButton1)
            .addContainerGap(212, Short.MAX_VALUE))
    );

    pack();
}// </editor-fold>                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    this.print();
}                                        

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new NewJFrame().setVisible(true);
        }
    });
}
// Variables declaration - do not modify                     
private javax.swing.JButton jButton1;
// End of variables declaration                   
 }

  import java.util.logging.Logger;
  import javax.swing.*;
  import java.awt.*;
  import java.sql.*;
  import java.util.*;
  import java.util.logging.Level;

  import net.sf.jasperreports.engine.*;

  import net.sf.jasperreports.view.*;

  class ReportViewer extends JFrame
  {
  public ReportViewer(String fileName,HashMap parameter)
 {
   super("Report");
   try
  {
   Connection con;
   String url="jdbc:mysql://localhost/project";
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con=(Connection) DriverManager.getConnection(url,"root","");
    JasperPrint print = JasperFillManager.fillReport(fileName, parameter, con);
    JRViewer viewer=new JRViewer(print);

    Container c=getContentPane();
    c.add(viewer);
   }
     catch (InstantiationException | IllegalAccessException ex) {
         Logger.getLogger(ReportViewer.class.getName()).log(Level.SEVERE, null, ex);
     }catch(ClassNotFoundException cnfe)
  {
    JOptionPane.showMessageDialog(null, cnfe);
  }
  catch(SQLException sqle)
  {
  JOptionPane.showMessageDialog(null, sqle);
  }
   catch(JRException jre)
   {
   JOptionPane.showMessageDialog(null, jre);
   }

  setBounds(100,40,600,500);
  setDefaultCloseOperation(DISPOSE_ON_CLOSE);
   }
   }

//Exception in code is

run:log4j:WARN No appenders could be found for logger          net.sf.jasperreports.extensions.ExtensionsEnvironment)
log4j:WARN Please initialize the log4j system properly
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError:net/sf   /jasperreports/compilers/GroovyEvaluator
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClass(JRClassLoader.java:338)
Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44

1 Answers1

0
  • Error : Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError:

  • Why getting this error ?

    This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime class paths.

How to solve this ?

  • I think this will solve your issue.
Community
  • 1
  • 1
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85