Error Compiling Report: java.lang.NoClassDefFoundE

2019-03-06 21:53发布

I have an error while compiling report the error is:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream

this is the code:

Map parameter = new HashMap();
parameter.put("customerId", notification_table.getValueAt(r, 0).toString());
ReportV sd = new ReportV();
sd.showReport(parameter);

this is the class I used:

import java.sql.*;
import java.util.Map;
import javax.swing.*;

import static javax.swing.JFrame.EXIT_ON_CLOSE;

import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.swing.JRViewer;

public class ReportV {

    Connection conn = null;

    void showReport(Map parameters) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            conn = DriverManager.getConnection("jdbc:odbc:pcn");
            JasperReport report = JasperCompileManager.compileReport("recipt.jrxml");
            JasperPrint print = JasperFillManager.fillReport(report, parameters, conn);
            JRViewer viewer = new JRViewer(print);
            viewer.setOpaque(true);
            viewer.setVisible(true);
            //make your JFrame visible
            this.add(viewer);
            this.setSize(300, 200);
            this.setVisible(true);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        } catch (Exception ex) {
            System.out.println("CAUSE: " + ex.getCause());
            System.out.println("MESSAGE" + ex.getMessage());
            System.out.println("LOCAL MESSAGE" + ex.getLocalizedMessage());
            ex.printStackTrace();
        }
    }
}

1条回答
做自己的国王
2楼-- · 2019-03-06 22:05

you have not imported the ServletOutputStream class.

import javax.servlet.ServletOutputStream;

I believe that's part of Java EE, so you will need that lib in your classpath in addition to the standard java jdk.

查看更多
登录 后发表回答