How do I fix a NoSuchMethodError?

前端 未结 29 2864
孤独总比滥情好
孤独总比滥情好 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:39

    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.

    App/  
      src/
         com.example/  
           Projection.java
    Test/  
      src/
         com.example/
           Projection.java
    

    After renaming the Test to the correct name "ProjectionTest.java" the exception went away.

提交回复
热议问题