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

Actually new to java, Spanish-speaking, so I do my best to make you understand me :). I created a program that manages a mysql database to store clients, customer information, etc. And generates (or tries ...) reports. I installed JasperReports from the Eclipse market (BTW using Eclipse Kepler). Following some tutorials, I made a way to create a report on the parameters. Its only parameter for identifying one customer. It's not a problem. The problem occurs when I click the button to create a report that contains the following code:

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 the Spanish variable names, captures the variable entered by the user, connects to the database, checks for the existence of such a user through its "dni", if it exists, generates a report, otherwise, a message error. When I executed it for the first time, apache.commons.logging was not found, I decided to import the apache commons libraries. But after that, the mistake was what I called this topic. I said: light cake, uploaded apache commons collections, imported cans ... and that’s 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 in order and it is there, but for some reason it looks like eclipse or java, or some alien does not find it. In any case, I was researching all over the Internet, and found this error, which was mainly solved by importing collections of collections ... not in my case. Eclipse kepler, java 7 and apache 4.0. Any vague idea ..? Thank you very much for taking the time to read it, sorry for my English and waiting for some light ..: D

+3
java eclipse classnotfoundexception
source share
3 answers

Well, the problem is solved! I just had to downgrade the collections to 3.2.1, and it worked, well .. partly because I had errors regarding other classes (joda-time, commons-digester and javax-servlet). And in some cases, downloading the latest version did not work, just downloading the previous version. So, after that, my report became flawless. Many thanks for your help!!:)

+5
source share

The best trick is to get classes that are referred to as missing. The missing class here is org/apache/commons/collections/ReferenceMap

Then find the jar file on Google, download the latest stable version and check if the jar file contains the missing class. Once you find the correct JAR file, add it to the project.

0
source share

I uploaded another .jar file for the general collection and it solved the problem. You can download it here: http://www.java2s.com/Code/Jar/o/Downloadorgapachecommonscollectionsjar.htm

-one
source share

All Articles