Alex Rivera | Logout

How do I fix a NoSuchMethodError?

Asked 2008-08-29T20:04:27.643
246

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

Edit
Report

2 Answers

289

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.

answered 2008-08-29T20:14:56.353
16

This is usually caused when using a build system like Apache Ant that only compiles java files when the java file is newer than the class file. If a method signature changes and classes were using the old version things may not be compiled correctly. The usual fix is to do a full rebuild (usually "ant clean" then "ant").

Sometimes this can also be caused when compiling against one version of a library but running against a different version.

answered 2008-08-29T20:04:36.910

Your Answer