【问题标题】:Call return type must be parameterized as Call<Foo> or Call<? extends Foo> Exception while calling retrofit API调用返回类型必须参数化为 Call<Foo> 或 Call<?调用改造 API 时扩展 Foo> 异常
【发布时间】:2021-02-02 22:19:08
【问题描述】:

以下是我使用的依赖项

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

下面是我调用改造 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);

这是改造APICLient

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

        return retrofit;
    }

下面是界面

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

下面是我得到的异常

 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

请帮助我。在此先感谢

【问题讨论】:

    标签: android android-recyclerview retrofit


    【解决方案1】:

    依赖关系

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

    调用改造 API

    在 ResponseBody 中获取响应,然后解析为 List of Object。

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

    界面

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

    【讨论】:

      猜你喜欢
      • 2016-02-18
      • 1970-01-01
      • 2020-02-14
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多