Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java "NoSuchMethodError"

I'm getting:

NoSuchMethodError: com.foo.SomeService.doSmth()Z 

Am I understanding correctly that this 'Z' means that return type of doSmth() method is boolean? If true, then that kind of method really does not exist because this method returns some Collection. But on the other hand if I call this method, I'm not assigning its return value to any variable. I just call this method like this:

service.doSmth(); 

Any ideas why this error occurs? All necessary JAR files exist and all other methods from this class seems to exist.

like image 858
vrm Avatar asked Sep 12 '10 15:09

vrm


People also ask

What causes NoSuchMethodError?

NoSuchMethodError is a runtime error in Java which occurs when a method is called that exists at compile-time, but does not exist at runtime. The Java Garbage Collector (GC) cannot free up the space required for a new object, which causes a java. lang. OutOfMemoryError .

What is NoSuchMethodError Java?

Class NoSuchMethodErrorThrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

What is Exception in thread main Java Lang NoSuchMethodError?

NoSuchMethodError: main Exception in thread "main" can come due to various reasons like: 1) The class which you are trying to run doesn't have the main method. 2) The signature of the main method is not correct.


2 Answers

Looks like method exists in classpath during compilation, but not during running of your application.

I don't think return type is a problem. If it was, it wouldn't compile. Compiler throws error when method call is ambiguous, and it is when two methods differ only by return type.

like image 164
amorfis Avatar answered Sep 19 '22 03:09

amorfis


Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

In short - a class/jar file at runtime is not the same that you used at compile time.

like image 43
Bozho Avatar answered Sep 19 '22 03:09

Bozho