简体   繁体   English

贾斯珀报告的Java代码中发现NoClass Def错误

[英]NoClass Def Found Error in Java Code of jasper report

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)
  • Error : Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: 错误: 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. 我认为可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM