真的很新鮮,在java中,講西班牙語的人,所以,盡我所能讓你瞭解我:)。我製作了一個程序,管理一個用於存儲客戶端的mysql數據庫,關於客戶端的信息等。並生成(或嘗試......)報告。我從Eclipse Market安裝了JasperReports(順便說一下,使用Eclipse Kepler)。遵循一些教程,我創造了通過參數創建報告的方式。它只是識別一個客戶端的一個參數。那不是問題。問題是當我點擊我的按鈕,生成報告,其中包含下面的代碼:java.lang.NoClassDefFoundError:org/apache/commons/collections/ReferenceMap
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.");
}
}
}
)
其中儘管變量西班牙語名字,抓由用戶輸入的變量,連接到數據庫,檢查這樣的存在用戶通過其「dni」,如果存在,生成報告,否則,消息錯誤。 當我第一次執行它時,找不到apache.commons.logging,我解決了導入apache commons庫的問題。但之後,錯誤是我題爲這個主題的那個。我說:簡單的蛋糕,下載的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$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 ......我仔細檢查了該庫是確定的,並且它的存在,但由於某些原因,它看起來像日食或Java ,或某種外星人,找不到它..無論如何,我在互聯網上進行了全面研究,發現這個錯誤,這主要是通過導入公共收藏品來解決的......不是我的情況。 Eclipse kepler,java 7和apache commons 4.0。任何模糊的想法..?非常感謝您花時間閱讀,對不起我的英文,並等待一些光..:D
也許問題出在這裏:轉到Java的問題/警告,並檢查是否沒有這個庫的警告。如果存在,請選擇快速修復程序 – rpax
您使用哪種版本的公用收藏? – mabbas
好吧,這個錯誤不會顯示在問題中,只在控制檯中顯示。所以沒有快速修復可用:)。我使用公共收藏4-4.0。提前致謝!! – neopablo2000