How do I fix a NoSuchMethodError?

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

    I ran into similar issue.

    Caused by: java.lang.NoSuchMethodError: com.abc.Employee.getEmpId()I
    

    Finally I identified the root cause was changing the data type of variable.

    1. Employee.java --> Contains the variable (EmpId) whose Data Type has been changed from int to String.
    2. ReportGeneration.java --> Retrieves the value using the getter, getEmpId().

    We are supposed to rebundle the jar by including only the modified classes. As there was no change in ReportGeneration.java I was only including the Employee.class in Jar file. I had to include the ReportGeneration.class file in the jar to solve the issue.

提交回复
热议问题