How do I fix a NoSuchMethodError?

John Meagher picture John Meagher · Aug 29, 2008 · Viewed 338.2k times · Source

I'm getting a NoSuchMethodError error when running my Java program. What's wrong and how do I fix it?

Answer

Vetle picture Vetle · Aug 29, 2008

Without any more information it is difficult to pinpoint the problem, but the root cause is that you most likely have compiled a class against a different version of the class that is missing a method, than the one you are using when running it.

Look at the stack trace ... If the exception appears when calling a method on an object in a library, you are most likely using separate versions of the library when compiling and running. Make sure you have the right version both places.

If the exception appears when calling a method on objects instantiated by classes you made, then your build process seems to be faulty. Make sure the class files that you are actually running are updated when you compile.