本文介绍了呼叫返回类型必须参数化为Call< Foo>.或致电< ;?扩展Foo>调用改造API时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我使用的依赖项
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
下面是我称为改造API的代码
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);
这是RetrofitAPICLient
This is RetrofitAPICLient
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);
以下是我得到的例外情况
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
请帮助我.谢谢!
推荐答案
依赖项
implementation "com.squareup.okhttp3:okhttp:4.9.0"
implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'
调用翻新API
在ResponseBody中获取响应,然后将其解析为对象列表.
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);
界面
@POST("GetCashMemoPunchingList")
Call<ResponseBody> getCashMemoPendingListObj(@Body RequestBody userData);
这篇关于呼叫返回类型必须参数化为Call< Foo>.或致电< ;?扩展Foo>调用改造API时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!