Reputation: 363
I was trying to build a sample Retrofit Java program taken from;
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.
Upvotes: 8
Views: 18455
Reputation: 5103
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.
Upvotes: 0
Reputation: 179
I had the same problem when I used the Alfresco Rest API in my JEE Application I solved the problem by adding these Maven dependencies
<properties>
<retrofit.version>2.1.0</retrofit.version>
<okhttp.version>3.4.1</okhttp.version>
</properties>
<dependencies>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>${retrofit.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>${retrofit.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava</artifactId>
<version>${retrofit.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>${okhttp.version}</version>
</dependency>
</dependencies>
Or you can add the correct Libraries (Jar files) in your build path if your are not using maven
I hope this will help you
Upvotes: 0
Reputation: 798
Here are some dependencies that might help you.
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.apache.httpcomponents:httpcore:4.4.5'
Try to clean your project and sync with gradle. Or try using the same version jar files in your project.
Or have you replaced this line with correct value.
@GET("/repos/{owner}/{repo}/contributors")
What is the response after calling the API. plz check the URL in the browser.
let me know if issue still persists.
Upvotes: 3
Reputation: 91
try to add this in gradle:
compile 'com.google.code.gson:gson:2.6.2'
it works well for me :)
Upvotes: 8
Reputation: 4346
Try this:
final RETROFIT_VERSION = '2.0.0'
final OKHTTP_VERSION = '3.2.0'
compile "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
compile "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
compile "com.squareup.okhttp3:okhttp:$OKHTTP_VERSION"
compile "com.squareup.okhttp3:okhttp-urlconnection:$OKHTTP_VERSION"
compile 'com.google.code.gson:gson:2.4'
Upvotes: 0