Search code examples
javaeclipsemavennosuchmethoderror

How to fix NoSuchMethodError in java


I am trying to run JDA Discord Bot, but getting this error:

[JDA MainWS-ReadThread] INFO net.dv8tion.jda.core.requests.WebSocketClient - Connected to WebSocket
[JDA MainWS-ReadThread] ERROR net.dv8tion.jda.core.requests.WebSocketClient - There was an error in the WebSocket connection
java.lang.NoSuchMethodError: org.json.JSONArray.iterator()Ljava/util/Iterator;
    at net.dv8tion.jda.core.requests.WebSocketClient.updateTraces(WebSocketClient.java:165)
    at net.dv8tion.jda.core.requests.WebSocketClient.onEvent(WebSocketClient.java:797)
    at net.dv8tion.jda.core.requests.WebSocketClient.handleEvent(WebSocketClient.java:745)
    at net.dv8tion.jda.core.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:903)
    at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:368)
    at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:270)
    at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:990)
    at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:749)
    at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:108)
    at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
    at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)

I can't find what's wrong,

I have asked at the JDA GitHub but they say I have to get the latest org.json which I already have. So I am confused.

Hope someone can help me there.


Solution

  • Indeed, the org.json.JSONArray.iterator() did not exist from the beginning, but was added later.

    Your pom.xml looks good, but in Referenced Libraries there is json-simple-1.1.1.jar instead of json-20180813.jar.

    Right-click the project and choose Maven > Update Project...