views:

77

answers:

3

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 it's 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..

+1  A: 

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.

Bozho
A: 

This is probably a difference between your compile-time classpath and you run-time classpath.

Here is what seems to be going on:

  • The code is compiled with a class path that defines the doSmth() method returning a boolean. The byte-code refers to the doSmth()Z method.
  • At runtime, the doSmth()Z method isn't found. A method returning a Collection is found instead.

To correct this problem, check your (compile time) classpath.

Vivien Barousse
+1  A: 

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.

amorfis