Search code examples
javaguavagoogle-sheets-api

How to solve "java.lang.NoSuchMethodError:" while working with Google spreadsheet api?


I am working on reading Google spreadsheet data on a button click. But I am stuck with this problem:

java.lang.NoSuchMethodError: com.google.common.base.Platform.stringIsNullOrEmpty(Ljava/lang/String;)Z
at com.google.common.base.Strings.isNullOrEmpty(Strings.java:69)
at com.google.api.client.util.Strings.isNullOrEmpty(Strings.java:34)
at com.google.api.client.auth.oauth2.AuthorizationCodeFlow.loadCredential(AuthorizationCodeFlow.java:249)
at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:113)

I have tried adding guava dependencies 27.1-jre, but it also not working. The code is working fine when I run the main method inside the class. But when I tried to call the method of this class in another class, it is throwing the exception.

What should I do?

These are the dependencies I have added:

"com.google.api-client" % "google-api-client-extensions" % "1.6.0-beta" ,
"com.google.apis" % "google-api-services-sheets" % "v4-rev1-1.21.0"  ,
"com.google.api-client" % "google-api-client-java6" % "1.30.7" ,
"com.google.oauth-client" % "google-oauth-client-jetty" % "1.30.5",

Solution

  • Answer:

    There is a object discrepency in your code due to the use of the google-collections library. Remove this to resolve the conflict.