Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Retrofit) Could not locate converter for class crashing app

So Retrofit 2.0.0 was recently released and theres not really any updated examples on how to use it, but im trying to implement it for a basic API call. Im getting a

java.lang.IllegalArgumentException: Unable to create converter for class`  

caused by

Caused by: java.lang.IllegalArgumentException: Could not locate converter for class orbyt.app.dataclass. Tried: * retrofit.OkHttpBodyConverterFactory 

When trying to make the api call.

like image 729
Orbit Avatar asked Sep 02 '15 01:09

Orbit


2 Answers

In Retrofit 2.0, Converter is not included in the package and when you are using Retrofit 2.0 Make Sure follow new URL pattern

Base URL: always ends with /

@Url: DO NOT start with /

Retrofit retrofit = new Retrofit.Builder()         .baseUrl(Constants.API_BASE_URL)         .addConverterFactory(GsonConverterFactory.create())         .build(); 

For more information about 2.0 Follow this link Retrofit 2.0: The biggest update

And also update build.gradle.

implementation "com.squareup.retrofit2:converter-gson:$retrofit_version" 

And add the extension in project level build.gradle file

ext { retrofit_version= "2.x.x" } 
like image 23
Ajit Kumar Dubey Avatar answered Sep 29 '22 05:09

Ajit Kumar Dubey


I was facing the same issue. I fixed it by adding :

compile 'com.squareup.retrofit2:converter-gson:<latest-version>' 

to my build.gradle

Then specify the converter when creating my Retrofit instance.

Retrofit retrofit = new Retrofit.Builder()             .baseUrl(Constants.API_BASE_URL)             .addConverterFactory(GsonConverterFactory.create())             .build(); 
like image 157
YacSrk Avatar answered Sep 29 '22 05:09

YacSrk