添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Exception in thread "OkHttp Dispatcher" java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)

Ask Question

I am using splunk java logging library and application is able to send logs to splunk server. But when we are starting application so we see below logs and those are very annoying because it gets printed again and again.

Exception in thread "OkHttp Dispatcher" java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)Lcom/google/gson/JsonElement;
    at com.splunk.logging.HttpEventCollectorErrorHandler$ServerErrorException.<init>(HttpEventCollectorErrorHandler.java:56)
    at com.splunk.logging.HttpEventCollectorSender$3.completed(HttpEventCollectorSender.java:308)
    at com.splunk.logging.HttpEventCollectorSender$4.onResponse(HttpEventCollectorSender.java:356)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Exception in thread "OkHttp Dispatcher" java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)Lcom/google/gson/JsonElement;
    at com.splunk.logging.HttpEventCollectorErrorHandler$ServerErrorException.<init>(HttpEventCollectorErrorHandler.java:56)
    at com.splunk.logging.HttpEventCollectorSender$3.completed(HttpEventCollectorSender.java:308)
    at com.splunk.logging.HttpEventCollectorSender$4.onResponse(HttpEventCollectorSender.java:356)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)to
                The version of Gson that you are using isn’t compatible with the version of Splunk that you are using. What are their respective versions? If you are using Spring Boot, as the question’s tags suggest, knowing the Spring Boot version would also be useful as Spring Boot provides dependency management for Gson.
– Andy Wilkinson
                Jun 27, 2021 at 6:58
                @AndyWilkinson - what makes you state that? how can a "version of JSON" affect whether Splunk can read it?
– warren
                Jun 28, 2021 at 21:28
                “Gson” wasn’t a typo. It’s a JSON processing library from Google: github.com/google/gson. The version in use here is binary incompatible with the version of Splunk.
– Andy Wilkinson
                Jun 29, 2021 at 6:29

Splunk has com.google.gson as a dependency. The installation is not detailed in the question but the library is not on the path as detailed in the manual.

gson-2.1.jar contains third-party tokenizers for parsing results for JSON output. Add this to your build path to display search results in JSON format using the ResultsReaderJson class.

NoSuchMethodError reports that the version found is too old for what is attempted. The dependency tree must be verified to locate which version is loaded first.

If Gson was absent, you’d get a ClassNotFoundException or NoClassDefFoundError. The NoSuchMethodError indicates that com.google.gson.JsonParser is already on the classpath and has been loaded but that the parseString(Ljava/lang/String;)Lcom/google/gson/JsonElement method is missing. – Andy Wilkinson Jun 29, 2021 at 6:33 Without the dependency tree, sorting imports is unfeasible.. JsonParser method appeared in 1.3. – Constantin Konstantinidis Jun 29, 2021 at 18:06 While JsonParser has existed since 1.3, the parseString method was added in this commit which means it's new in 2.8.6. – Andy Wilkinson Jun 29, 2021 at 18:46

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.