Not able to resolve java.lang.NoSuchMethodError with GSON library

Viewed 13268

I was trying to build a sample Retrofit Java program taken from;

https://github.com/square/retrofit/blob/master/samples/src/main/java/com/example/retrofit/SimpleService.java

I included required dependent jars (retrofit-2.0.0.jar,converter-gson-2.0.0.jar,okhttp-3.0.0-RC1.jar,okio-1.6.0.jar and gson-2.0.jar) to the build path.

I encounter the following exception while trying to run the application.

Exception in thread "main" java.lang.NoSuchMethodError: com.google.gson.Gson.getAdapter(Lcom/google/gson/reflect/TypeToken;)Lcom/google/gson/TypeAdapter;
at retrofit2.converter.gson.GsonConverterFactory.responseBodyConverter(GsonConverterFactory.java:63)
at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:325)
at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:308)
at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:651)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:166)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
at com.sun.proxy.$Proxy0.contributors(Unknown Source)
at SimpleService.main(SimpleService.java:40)

Am I missing any dependent jar?

I am trying to use Retrofit in standalone Java application and was testing samples to get used to it. It will be great if someone could point me to a simple sample program that demonstrates the working of Retrofit, even a sample of earlier version would be good.

5 Answers

Late answer, yes, but I struggled with this for a week. Wanted to post the solution that worked for me.

If you get this issue it could be from the existing crawler being FUBAR. As a workaround you can go back to the previous version of the crawler by opting out of the newly released one.

Here's how to opt-out:

Sign in to your Play Console. Select an app. Select Release management > Pre-launch report > Settings. In the “Pre-launch report version” section, move the Opt-out switch to the right until it turns blue. After this, the launch reports appear correctly again.

Related