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

27,667

Well, problem solved! I just had to downgrade collections to 3.2.1, and that worked, well.. partially, because i kept having errors about other classes (joda-time, commons-digester and javax-servlet). And in some cases, downloading latest version didnt work, just downloading a previous one. So, my report came flawless after that. Thank you very much for your help!! :)

Share:
27,667
neopablo2000
Author by

neopablo2000

Updated on July 09, 2022

Comments

  • neopablo2000
    neopablo2000 almost 2 years

    Really newbie in java, Spanish-speaker, so, ill do my best for you to understand me :). I made a program which manages a mysql database for storing clientes, information about clients, etc. And generates (or trying too...) reports. I installed JasperReports from Eclipse Market (BTW, using Eclipse Kepler). Following some tutorials, i made my way into creating a report by parameters. Its just one parameter to identify one client. Thats not the problem. The problem comes when i click my button to generate the report, which contains the code below:

    JButton btnOk = new JButton("OK");
        btnOk.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                String doc = jftxtDni.getText();
                String sql;
                boolean respuesta = false;
                ConexionBaseDatos cc = new ConexionBaseDatos();
    
                sql = "SELECT * FROM clientes WHERE DNI = '"+doc+"'";
    
                rs = cc.Consultar(sql);
    
                    try 
                    {
                        while (rs.next())
                        {
                        respuesta = true;
                        }
                    }
                    catch (SQLException e) 
                    {
                        JOptionPane.showMessageDialog(null, "error sql: "+e.getMessage());
                    }    
    
                    if (respuesta)
                    {
                        ConexionBaseDatos cd = new ConexionBaseDatos();
                        Connection cn = cd.Conectar();
                        JasperReport jr = null;
                        String archivo = "src/reportes/Tree.jasper";
                        try
                        {
                            HashMap<String, Object> parametro = new HashMap<String, Object>();
                            parametro.put("dni", doc);
                            jr = (JasperReport) JRLoader.loadObjectFromFile(archivo);
                            JasperPrint jp = JasperFillManager.fillReport(jr,parametro,cn);
                            JasperViewer jv = new JasperViewer(jp);
                            jv.setVisible(true);
                            jv.setTitle("Informe de cliente");
    
                        } 
                        catch (JRException e)
                        {
                            JOptionPane.showMessageDialog(null, "error Jasper: "+e.getMessage());;
                        }
    
                    }   
                    else
                    {
                        JOptionPane.showMessageDialog(null, "No existe el cliente en la base de datos, verifique.");
                    }
    
                    }
                }
            )
    

    which despite spanish names of variables, catchs a variable typed by user, connects to database, check the existence of such a user through its "dni", if exists, generates the report, otherway, a message error. When i executed it first time, apache.commons.logging not found appeared, wich i solved importing apache commons libraries. But after that, the error was the one i titled this topic. I said: easy cake, downloaded apache commons collections, imported jars... and that is it! I thought... but no way.. i get:

    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/collections/ReferenceMap
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.<init>(DefaultExtensionsRegistry.java:97)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(ClassUtils.java:59)
    at net.sf.jasperreports.extensions.ExtensionsEnvironment.createDefaultRegistry(ExtensionsEnvironment.java:82)
    at net.sf.jasperreports.extensions.ExtensionsEnvironment.<clinit>(ExtensionsEnvironment.java:69)
    at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:123)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61)
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:179)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:81)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:849)
    at formularios.ImprimirCliente$2.actionPerformed(ImprimirCliente.java:143)
    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)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.ReferenceMap
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 55 more
    

    ...sooooo... i double checked the library is ok, and its there, but for some reason, it looks like eclipse or java, or some kind of alien, doesnt find it.. anyway, i did research all over the internet, and found this error, wich was mostly solved by importing commons collections... not my case. Eclipse kepler, java 7, and apache commons 4.0. Any vague idea..? Thank you very much for taking time to read it, sorry for my english and waiting for some light.. :D