How do I fix a NoSuchMethodError?

前端 未结 29 2860
孤独总比滥情好
孤独总比滥情好 2020-11-21 05:08

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

相关标签:
29条回答
  • 2020-11-21 05:53

    NoSuchMethodError : I have spend couple of hours fixing this issue, finally fixed it by just renaming package name , clean and build ... Try clean build first if it doesn't works try renaming the class name or package name and clean build...it should be fixed. Good luck.

    0 讨论(0)
  • 2020-11-21 05:55

    Note that in the case of reflection, you get an NoSuchMethodException, while with non-reflective code, you get NoSuchMethodError. I tend to go looking in very different places when confronted with one versus the other.

    0 讨论(0)
  • 2020-11-21 05:56

    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.

    0 讨论(0)
  • 2020-11-21 05:56

    If using Maven or another framework, and you get this error almost randomly, try a clean install like...

    clean install
    

    This is especially likely to work if you wrote the object and you know it has the method. Worked for me.

    0 讨论(0)
  • 2020-11-21 05:57

    Above answer explains very well ..just to add one thing If you are using using eclipse use ctrl+shift+T and enter package structure of class (e.g. : gateway.smpp.PDUEventListener ), you will find all jars/projects where it's present. Remove unnecessary jars from classpath or add above in class path. Now it will pick up correct one.

    0 讨论(0)
  • 2020-11-21 05:58

    I had a similar problem with my Gradle Project using Intelij. I solved it by deleting the .gradle (see screenshot below) Package and rebuilding the Project. .gradle Package

    0 讨论(0)
提交回复
热议问题