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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22847455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 18:21:29  来源:igfitidea点击:

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

javaeclipseclassnotfoundexception

提问by neopablo2000

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:

真的是 Java 新手,讲西班牙语,所以,我会尽力让你理解我:)。我制作了一个程序,用于管理 mysql 数据库,用于存储客户、有关客户的信息等。并生成(或尝试...)报告。我从 Eclipse Market(顺便说一句,使用 Eclipse Kepler)安装了 JasperReports。按照一些教程,我开始按参数创建报告。它只是识别一个客户端的一个参数。那不是问题。当我单击我的按钮生成报告时出现问题,其中包含以下代码:

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:

尽管变量的西班牙语名称,捕获用户键入的变量,连接到数据库,通过其“dni”检查此类用户是否存在,如果存在,则生成报告,否则,消息错误。当我第一次执行它时,出现了 apache.commons.logging not found,我解决了导入 apache 公共库的问题。但在那之后,错误就是我给这个话题命名的那个。我说:简单的蛋糕,下载的 apache 公共收藏,进口的罐子……就是这样!我想……但没办法……我明白了:

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.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.access0(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.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.run(Unknown Source)
at java.net.URLClassLoader.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

...sooooo...我仔细检查了图书馆是好的,它在那里,但出于某种原因,它看起来像 eclipse 或 java,或者某种外星人,没有找到它......无论如何,我做了整个研究互联网,发现这个错误,主要是通过导入公共集合来解决的......不是我的情况。Eclipse 开普勒、java 7 和 apache commons 4.0。任何模糊的想法..?非常感谢您花时间阅读它,对不起我的英语并等待一些光......:D

回答by neopablo2000

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!! :)

嗯,问题解决了!我只需要将集合降级到 3.2.1,这很有效,部分原因是因为我一直有关于其他类(joda-time、commons-digester 和 javax-servlet)的错误。在某些情况下,下载最新版本不起作用,只需下载以前的版本即可。所以,在那之后,我的报告完美无缺。非常感谢您的帮助!!:)

回答by newbie

I downloaded a different .jar file for common collection and it resolved the issue. You can download it here : http://www.java2s.com/Code/Jar/o/Downloadorgapachecommonscollectionsjar.htm

我下载了一个不同的 .jar 文件用于公共集合,它解决了这个问题。你可以在这里下载:http: //www.java2s.com/Code/Jar/o/Downloadorgapachecommonscollectionsjar.htm

回答by dilanSachi

The better trick is to get the classes that are mentioned as missing. In here the missing class is org/apache/commons/collections/ReferenceMap

更好的技巧是获取被提及为缺失的类。在这里缺少的课程是org/apache/commons/collections/ReferenceMap

Then google for the jarfile and download the newest stable verion and check if the jar file contains the missing class. Once you find the correct jar file, add it to the project.

然后谷歌搜索jar文件并下载最新的稳定版本并检查jar文件是否包含缺少的类。找到正确的 jar 文件后,将其添加到项目中。