Call return type must be parameterized as Call<Foo> or Call<? extends Foo> Exception while calling retrofit API

Viewed 647

Below are the Dependencies which I have used

implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'

Below is the code which I am calling retrofit API

RequestBody jsonBody = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),(jsonInput));

            RetrofitAPI cashMemoService = RetrofitAPICLient.getClient().create(RetrofitAPI.class);
            Call<List<CashMemoDetails>> call = cashMemoService.getCashMemoPendingListObj(jsonBody);

This is RetrofitAPICLient

public static Retrofit getClient(){
        if(retrofit == null){
            retrofit = new Retrofit.Builder()
                    .baseUrl(newBseURL)
                    .client(okHttpClient)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }

        return retrofit;
    }

Below is the Interface

@POST("GetCashMemoPunchingList")
    Call<List<CashMemoDetails>> getCashMemoPendingListObj(@Body RequestBody userData);

Below is the exception which I am getting

 2020-10-20 10:59:47.320 27155-27155/ W/com.hpcl.gsa2: Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (greylist,core-platform-api, reflection, allowed)
    2020-10-20 10:59:47.335 27155-27155/ W/System.err: java.lang.IllegalArgumentException: Unable to create call adapter for interface g.g
   55-27155/ W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
    2020-10-20 10:59:47.336 27155-27155/ W/System.err: Caused by: java.lang.IllegalArgumentException: Call return type must be parameterized as Call<Foo> or Call<? extends Foo>
    2020-10-20 10:59:47.336 27155-27155/ W/System.err:  ... 22 more

Please help me on this.Thanks in advance

1 Answers

Dependencies

implementation "com.squareup.okhttp3:okhttp:4.9.0"
implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'

Calling Retrofit API

Get response in ResponseBody and then parse it to List of Object.

RetrofitAPI cashMemoService = RetrofitAPICLient.getClient().create(RetrofitAPI.class);
Call<ResponseBody> call = cashMemoService.getCashMemoPendingListObj(jsonBody);

Interface

@POST("GetCashMemoPunchingList")
Call<ResponseBody> getCashMemoPendingListObj(@Body RequestBody userData);
Related