How do I fix a NoSuchMethodError?

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

    For me it happened because I changed argument type in function, from Object a, to String a. I could resolve it with clean and build again

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

    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:

    filenotnull=/DayMoreConfig.conf
    16-07-2015 05:02:10:ussdgw-1: Open TCP/IP connection to SMSC: 10.149.96.66 at 2775
    16-07-2015 05:02:10:ussdgw-1: Bind request: (bindreq: (pdu: 0 9 0 [1]) 900 900 GEN 52 (addrrang: 0 0 2000) ) 
    Exception in thread "main" java.lang.NoSuchMethodError: gateway.smpp.PDUEventListener.<init>(Lgateway/smpp/USSDClient;)V
            at gateway.smpp.USSDClient.bind(USSDClient.java:139)
            at gateway.USSDGW.initSmppConnection(USSDGW.java:274)
            at gateway.USSDGW.<init>(USSDGW.java:184)
            at com.vinaphone.app.ttn.USSDDayMore.main(USSDDayMore.java:40)
    
    -bash-3.00$ 
    

    These problems are caused by the concomitant 02 similar class (1 in src, 1 in jar file here is gateway.jar)

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

    In my case I had a multi module project and scenario was like com.xyz.TestClass was in module A and as well as in module B and module A was dependent on module B. So while creating a assembly jar I think only one version of class was retained if that doesn't have the invoked method then I was getting NoSuchMethodError runtime exception, but compilation was fine.

    Related : https://reflectoring.io/nosuchmethod/

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

    The problem in my case was having two versions of the same library in the build path. The older version of the library didn't have the function, and newer one did.

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

    Just adding to existing answers. I was facing this issue with tomcat in eclipse. I had changed one class and did following steps,

    1. Cleaned and built the project in eclpise

    2. mvn clean install

    3. Restarted tomcat

    Still I was facing same error. Then I cleaned tomcat, cleaned tomcat working directory and restarted server and my issue is gone. Hope this helps someone

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

    If you have access to change the JVM parameters, adding verbose output should allow you to see what classes are being loaded from which JAR files.

    java -verbose:class <other args>
    

    When your program is run, the JVM should dump to standard out information such as:

    ...

    [Loaded junit.framework.Assert from file:/C:/Program%20Files/junit3.8.2/junit.jar]

    ...

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