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"
Share:
10,524
Héctor
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, 2022

Comments

  • Héctor
    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
    Radu over 8 years
    Can you please explain why that is?
  • Blackbelt
    Blackbelt over 8 years
    @Radu why that is what ?
  • Radu
    Radu over 8 years
    Why has Retrofit 2.0 decided to wrap everything in a Call<T>. I think it's to encapsulate the sync/async behavior?
  • Blackbelt
    Blackbelt over 8 years
    @Radu, it is highly possibile. You should ask square to be 100% sure
  • gbruscatto
    gbruscatto almost 4 years
    Ka-chow! I forgot the suspend prefix. Thank you! :)
  • Ritzor
    Ritzor over 3 years
    Ops..why android? why?
  • user10997009
    user10997009 over 3 years
    Hello @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
    Nouman Ghaffar about 2 years
    saved the day...