Retrofit 2.0: Unable to create call adapter for class
10,524
Solution 1
Accordingly to the code you posted you have to change from
List<ArticleResource> getArticles();
to
Call<List<ArticleResource>> getArticles();
You might also want to call explicitly addConverterFactory
to set the converter you want to use
Solution 2
This issue can also occur if you are using kotlin
coroutines
and the function is not suspend
function
public interface ArticlesAPI {
@GET("url.../habits/progress/")
suspend fun getHabitsTasks(): BaseResponse<HabitResModel>
}
Solution 3
Change the retrofit2 version to latest in build.gradle file
implementation "com.squareup.retrofit2:retrofit:2.9.0"
Author by
Héctor
Dev by trade, Ops for necessity. Freelance software engineer, focused on backend development and cloud native architectures.
Updated on July 21, 2022Comments
-
Héctor almost 2 years
I'm using Retrofit 2.0-beta1. How can I make a simple synchronous request and deserialize a JSON response as a POJO list? This is my interface:
public interface ArticlesAPI { @GET("/articles") List<ArticleResource> getArticles(); }
and
public class ArticleResource { public String id; public String name; public Article toArticle() { return new Article(id, name); } }
but I get this error:
> Unable to create call adapter for > java.util.List<com.bla.bla.rest.resources.ArticleResource>
Retrofit build
Retrofit retrofit = (new Retrofit.Builder()).baseUrl(this.baseUrl).build(); ArticlesAPI api = retrofit.create(ArticlesAPI.class);
-
Radu over 8 yearsCan you please explain why that is?
-
Blackbelt over 8 years@Radu why that is what ?
-
Radu over 8 yearsWhy has Retrofit 2.0 decided to wrap everything in a Call<T>. I think it's to encapsulate the sync/async behavior?
-
Blackbelt over 8 years@Radu, it is highly possibile. You should ask square to be 100% sure
-
gbruscatto almost 4 yearsKa-chow! I forgot the suspend prefix. Thank you! :)
-
Ritzor over 3 yearsOps..why android? why?
-
user10997009 over 3 yearsHello @Rahul,I am new with MVVM and corotuines,i got the same problem.Can you help me.Here is my code github.com/diptoroy/RetrofitKotlin
-
Nouman Ghaffar about 2 yearssaved the day...