0

So I've successfully created my report and I've been trying to get an int variable as a parameter into my query, but I keep on getting this error:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ReferenceMap

The code I have to deliver the parameter is this:

private void report(){
    try {
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/DB?autoReconnect=true&useSSL=false", "root", "root");

        Map parameter = new HashMap();

        parameter.put("ID", last_Report);

        String path = System.getProperty("user.dir") + "/src/Reports/Report1.jrxml";

        JasperReport content = JasperCompileManager.compileReport(path);

        JasperPrint printRep = JasperFillManager.fillReport(content, parameter, con);

        JasperViewer.viewReport(printRep);

    } catch (JRException ex) {
        Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
}

I already checked if the last_Report variable has a proper value, and it does have an int, and when I print the Map, I get this: [{ID=25}].

I have my parameter declared here:

<parameter name="ID" class="java.lang.Integer">
    <defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>

And this is my query:

Select * from Reports where reports_ID = $P{ID};

Edit: I removed and re added all the libraries, and now I'm getting this:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester

Libraries I currently have:

  • mysql-connector-java-5.1.45-bin.jar
  • commons-beanutils-1.9.3.jar
  • commons-collections4-4.1.jar
  • commons-digester3-3.2.jar
  • commons-logging-1.2.jar
  • itext7-7.0.2.zip
  • jfreechart-1.0.19-demo.jar
  • jxl.jar
  • poi-3.17.jar
  • jasperreports-6.5.1.jar
  • jasperreports-fonts-6.5.1.jar
  • jasperreports-javaflow-6.5.1.jar
Alex K
  • 22,315
  • 19
  • 108
  • 236

1 Answers1

1
java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ReferenceMap

Looks like you might have missed adding the commons-collection jar to your project lib. What version of JasperReports you are using? If it is 6.x, try adding commons-collections-3.2.2.jar into your project classpath.

sdman
  • 146
  • 5