views:

57

answers:

2

So, I'm working in eclipse were everything compiles and runs correctly. However, when compiling under ant for the build server, A large number of tests fail with a NoSuchMethodError saying:

class A implements B
interface B extends C
C requires method getSyncID() // standard getter for an int field.
A.java contains getSyncID()
A.class contains getSyncID()

and yet the Error is still thrown.

Does anyone know how the hell this could happen? how to fix it.

+1  A: 

This happens when class files get out of sync with each other; in other words, one was compiled to a new version while another one wasn't. Try cleaning and rebuilding from scratch.

Mark Peters
No the compiler seems to be working correctly. I can run test over the ant compiled class files and they all pass and as I've stated the getSyncID method is present in the .class files
A: 

The problem occurs when the class loader discovers that a method in one class (A) calls a method in another class (B) that does not exist. The root cause is that the class B that the class loader sees is different to the class B that the compiler saw when it compiled A.

The most common cause of this problem is as @MarkPeters says - that your ".class" files have gotten out of sync with the ".java" files and need to be recompiled from scratch.

Another possibility is that you have an old copy of some of the ".class" files on the classpath when you try to run the application.

But either way, you have to believe the classloader. If it says that the method is not there, then it is not there ... in the particular ".class" file that it is loading. If the method appears to be there in the ".class" file, then that is evidence that you are loading a different version of the file earlier in the classpath!

Stephen C