Exception “java.lang.NoSuchMethodError: org.object

2019-06-24 04:36发布

问题:

I am using Jasper Reports and am using following libraries in my class path

jasperreports-4.5.1.jar
common-digester3-3.2.jar
common-digester2.1.jar
castor-1.2.jar
commons-beanutils-1.8..0.jar
commons-collections-2.1.1.jar
commons-logging-1.1.1.jar
groovy-1.2.6.jar
asm-2.2.3.jar
asm-3.1.jar
asm-all-3.1.jar
antlr-3.3.1.1.jar
jtds-1.2.5.jar

I got the following exception

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
at org.codehaus.groovy.control.CompilationUnit.createClassVisitor(CompilationUnit.java:791)
at org.codehaus.groovy.control.CompilationUnit$14.call(CompilationUnit.java:755)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:967)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:546)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:524)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:501)
at net.sf.jasperreports.compilers.JRGroovyCompiler.compileUnits(JRGroovyCompiler.java:96)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:188)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:212)
at Utilities.ReportDriver.runReport(ReportDriver.java:81)
at jewelleryerpapplication.GUI.MainReports.jbtnViewReportActionPerformed(MainReports.java:544)
at jewelleryerpapplication.GUI.MainReports.access$100(MainReports.java:18)
at jewelleryerpapplication.GUI.MainReports$2.actionPerformed(MainReports.java:210)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)

on executing the following code:

 JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, param, jdbcConnection);
 JasperViewer.viewReport(jasperPrint);

What have I done wrong? How can I fix this or debug it further?

回答1:

Note that you have two different versions of ASM listed. This is a very common problem with that library because so many other libraries use it under the hood and because Java's classpath mechanism doesn't allow for using different versions of the same library. (This happens all the time between Groovy and Hibernate.) So when you set up your classpath, one library wants version 2.2.3, and one wants 3.1. When looking up classes, though, the first one on the classpath wins. In your case, Groovy is trying to call a constructor on ClassWriter that doesn't exist in whichever version won (2.2.3, if you listed them in the actual classpath order). When you have this situation, where different versions are being demanded, all you can do is pick a version and cross your fingers. Try it out to see if it works everywhere you need it to. Most likely, everything will be fine if you use the newer ASM version (3.1). That's been my experience, anyway. If you can't find a version that works for everything, you might have a big problem on your hands.



回答2:

I had a similar error message. It wasn't depending on the ASM, but on the used groovy library groovy-x.x.x.jar. Beware - you have to use the groovy-all-x.x.x.jar in order to get this work.