Why does my method throw a NoSuchMethodError? - java

I have implemented successfully the reflectionEquals method, with a list of excluded fields.
return EqualsBuilder.reflectionEquals(this, obj, new String[] {"files", "notes", "status"});
However, I recently compiled my program on Java 1.5 and now I get the following error when the program hits the above line:
java.lang.NoSuchMethodError:
org.apache.commons.lang.builder.EqualsBuilder.=
reflectionEquals(Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/String;)Z
If anyone has an insight on why the method does not exist at runtime, I would appreciate it

Every NoSuchMethodError that I've ever encountered has (eventually) been found to be a mismatch between the version of an external library on the classpath at compile time vs. the version of the library on the classpath at runtime (i.e. - in this case, you would have a different version of apache commons on your classpath when the application is compiled than when it is running.)
The method was definitely there when your code was compiled - or a compiler error would've been thrown.
Check the versions of commons-lang.jar on your classpaths - I'm betting you'll find a mismatch.
It's worth noting that this is NOT a MISSING jar file - that would throw a ClassNotFoundException (maybe eventually followed by a NoClassDefFoundError.)

This is likely a var args problem. Be sure to recompile everything in java 1.5 and be sure you are running it on java 1.5, and be sure you reference the same jar at compilation as at runtime.

You may have an older version on your runtime classpath.
Get the latest version of Apache Commons Lang

Related

Java .class file disappeares as soon as I run the project

I've been on a project where I build tetris that has multiplayer, and it's been working for a couple of days with no problem, but now suddenly there's this exception:
Exception in thread "main" java.lang.NoClassDefFoundError: Game/Piece
This basically means it can't find the .class of my class called Piece, but whenever I do a "clean and build" the .class file appears, then instantly disappears when I run the project.
This is my project structure (running with JDK 16, in netbeans):
Is there a reason for this exception?
My JAVA_HOME variable: jdk1.8.0_131.
While it's possible that this is due to a classpath mismatch between compile-time and run-time, it's not necessarily true.
It is important to keep two or three different exceptions straight in our head in this case:
java.lang.ClassNotFoundException This exception indicates that the class was not found on the classpath. This indicates that we were trying to load the class definition, and the class did not exist on the classpath.
java.lang.NoClassDefFoundError This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it. This is different than saying that it could not be loaded from the classpath. Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again). The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.
And this question has been asked before.
This type of error can appear for multiple reasons :
Because the compiler is too different than the JVM, specially with new Java syntax.
Personally, I had this type of error by running Java 16 code with Java 8 JRE, and I fix it by removing the package with the Java 16 code.
Because you were using deprecated class, which have been removed since this date.
So, to fix your issue, there is multiple ways:
Use same Java in Netbeans and in your project config (to prevent change)
Upgrade your Java JRE installed (instead of old Java 8 version) to have both Java 16
Downgrade Netbeans JDK to Java 8 to have both Java 8
The objective is to use the same JVM than JDK, to see all warns/error that are linked to your current code.
So apperantly I had a warning (not an error) when compiling, it said something was depracated, so I had to add a compiler option name -Xlint:(something here I can't remember), so when I compiled it the issue was obvious, JFrame.hide() is a depracated function so I just had to remove it. It's weird that the runtime error was "NoClassDefFoundError" which has nothing to do with the issue.

gwt-dev - Librairies with same package name

This is my first post on stackoverflow, please be indulgent.
Within my project, I use the library commons-digester-1.8.
Following a need, I now use the library gwt-dev-2.3.0.
When launching the application I get this error :
Exception caught while initializing context java.lang.NoSuchMethodError: org/apache/commons/digester/xmlrules/DigesterLoader.createDigester(Lorg/xml/sax/InputSource;)Lorg/apache/commons/digester/Digester;
at fr.cnasea.commons.webfwk.util.config.lecture.XMLDigesterReader.getConfig(XMLDigesterReader.java:157)
at fr.cnasea.commons.webfwk.util.config.CnaseaAppConfigurator.configure(CnaseaAppConfigurator.java:76)
at fr.cnasea.osiris.commons.gwt.server.Config.contextInitialized(Config.java:47)
It turns out that the two libraries have the same class in the same package with the same method:
Same class
Since the use of gwt-dev, it is the method of this library which is called.
I tried to use newer versions of gwt-dev but the environment makes it not possible
How can I fix it?
Thanks for your help :)
(From my answer to your same question on the github project)
The gwt-dev.jar should not be on your server classpath - it is only used to compile your application. The same is true for gwt-user.jar. Only gwt-servlet.jar (and possibly requestfactory-server.jar) should end up on your server classpath, the others are intended only to be present when compiling, either to do the work of compiling, or to provide the compiler the classes you need.

PreparedStatement with list of parameters in a IN [duplicate]

What are the possible causes for ABstractMethodError?
Exception in thread "pool-1-thread-1" java.lang.AbstractMethodError:
org.apache.thrift.ProcessFunction.isOneway()Z
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:51)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
at com.gemfire.gemstone.thrift.hbase.ThreadPoolServer$ClientConnnection.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
It usually means that you are using an old version of an interface implementation which is missing a new interface method. For example java.sql.Connection interface got a new getSchema method in 1.7. If you have 1.6 JDBC driver and call Connection.getSchema you will get AbstractMethodError.
The simple answer is this: some code is trying to call a method which is declared abstract. Abstract methods have no body and cannot be executed. Since you have provided so little information I can't really elaborate more on how this can happen since the compiler usually catches this problem - as described here, this means the class must have changed at runtime.
From documnentation of AbstractMethodError
Thrown when an application tries to call an abstract method. Normally,
this error is caught by the compiler; this error can only occur at run
time if the definition of some class has incompatibly changed since
the currently executing method was last compiled.
A kind of special case of the above answer.
I had this error, because I was using a spring-boot-starter-parent (e.g. 2.1.0.RELEASE uses spring version: 5.1.2.RELEASE) but I also included a BOM, that also defined some spring dependencies, but in an older version (e.g. 5.0.9.RELEASE).
So one thing to do, is check your dependency tree (in Eclipse e.g. you can use the Dependency Hierarchy) if you are using the same versions.
So one solution could be that you upgrade the spring dependencies in your BOM, another one could be that you exclude them (but depending on the amount, this could be ugly).
If you download any project zip file, after unzipping them and importing into Android Studio, you are unable to run the project because this error happened.
I got out of the problem by deleting my android studio, then download and install the new version.
I truly hope it help.
If you you are getting this error on the implemented methods, make sure you have added your dependencies correctly as mentioned in this thread.
As Damian quoted :
Normally, this error is caught by the compiler; this error can only
occur at run time if [...]
I had the same error that was not caught by the compiler but at runtime. To solve it I only compiled again without giving the code any modification.
if you are getting this error on a minified build using Proguard then check if the class is a POJO class and if so then exclude it from the Proguard using the below rule:
-keep class your.application.package.pojo.** {*;}
I had the same error when I imported an eclipse project into intellij ide.. I tried to import it without .iml file then my problem was solved
I get this problem when I update my kotlin plugin to a new version .... the problem is that my pom file is using the older kotlin version .. I guess it might help someone if he is doing this mistake
I am getting various of these and others infrequently on android.. I have to clean everything change som configuration rebuild change configuration again to normal somehow just the build tools don't rebuild everything they should for whatever reason (Android gradle bug obviously).

package com.sun.xml.internal.messaging.saaj.soap.dynamic does not exist

I am trying to compile a java file, which uses package com.sun.xml.internal.messaging.saaj.soap.dynamic, using ANT-1.9.3 but I'm receiving error
package com.sun.xml.internal.messaging.saaj.soap.dynamic does not
exist
I tried compiling both JDK7 and JDK 8 and getting the same error.
I can see the package exist inside rt.jar of both JDK. I have set JAVA_HOME also properly.
Can someone help me to resolve this issue?
Unfortunately for you, this behaviour is probably intentional and your usage is deliberately unsupported. If your code used to compile under Java6 and now doesn't under Java7 or Java8 then you've basically fallen foul of
From one release to another, these classes may be removed, or they may be moved from one package to another
http://www.oracle.com/technetwork/java/faq-sun-packages-142232.html
See also http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6778491 for a technical description of a possible cause of not being able to compile a class which references a 'com.sun.*' class but which throws the same compiler error you're seeing despite the fact that the referenced class exists in rt.jar. Also for the kind of response which Oracle give to bug reports relating to it;)
Unfortunately, using undocumented, unsupported APIs often has this kind of 'bite you in the posterior' kind of effect.
Please add the line, < compilerarg line="-XDignore.symbol.file" compiler="modern"/ > for < javac > tag in your build.xml. This should solve your problem. It solved for me.
For reference you can view the forum link
http://www.icesoft.org/JForum/posts/list/19871.page#sthash.srrN9Ijk.dpbs

Axis: getting java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: Bad version number in .class file

I've been getting this error several times, and preceeding it I'm also getting:
[JavaUtils] Unable to find required classes
(javax.activation.DataHandler and javax.mail.internet.MimeMultipart).
Attachment support is disabled
I've added activation.jar and mail.jar to my classpath but it's no good. Could anybody help me with this.
Thanks in advance,
PS: The issue occurs when invoking a certain web-services.
EDIT: After deploying the project and trying to acces ws for the first time I got the exception, then, invoking the ws again does not cause any exception throwing. This is getting very weird.
The error in your subject line happens when you try to use .class files compiled with the compiler for Java version X with the runtime for java version Y, X>Y. You need to use a more recent runtime, or you need to 'compile down' with the appropriate options to javac.

Categories

Resources