I'm getting a NoSuchMethodError
error when running my Java program. What's wrong and how do I fix it?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
If you are writing a webapp, ensure that you don't have conflicting versions of a jar in your container's global library directory and also in your app. You may not necessarily know which jar is being used by the classloader.
e.g.
It means the respective method is not present in the class:
If your file name is different than the class name which contain main method then it may be the possibility that this error may cause.
Try this way: remove all .class files under your project directories (and, of course, all subdirectories). Rebuild.
Sometimes
mvn clean
(if you are using maven) does not clean .class files manually created byjavac
. And those old files contain old signatures, leading toNoSuchMethodError
.I fixed this problem in Eclipse by renaming a Junit test file.
In my Eclipse work space I have an App project and a Test project.
The Test project has the App project as a required project on the build path.
Started getting the NoSuchMethodError.
Then I realized the class in the Test project had the same name as the class in the App project.
After renaming the Test to the correct name "ProjectionTest.java" the exception went away.
These problems are caused by the use of the same object at the same two classes. Objects used does not contain new method has been added that the new object class contains.
ex:
These problems are caused by the concomitant 02 similar class (1 in src, 1 in jar file here is gateway.jar)