我已經創建了一個自定義實現Call<T>
,這裏是沒有自定義代碼的自定義類,只是轉發代碼供您查看。翻新:導致:java.lang.IllegalArgumentException:無法找到CustomClass的調用適配器
public class CachedCall<T> implements Call<T> {
private final Call<T> delegate;
public CachedCall(Call<T> delegate) {
this.delegate = delegate;
}
@Override
public Response<T> execute() throws IOException {
return delegate.execute();
}
@Override
public void enqueue(Callback<T> callback) {
delegate.enqueue(callback);
}
public void enqueueWithCache(final CachedCallback<T> callback) {
delegate.enqueue(callback);
}
@Override
public boolean isExecuted() {
return delegate.isExecuted();
}
@Override
public void cancel() {
delegate.cancel();
}
@Override
public boolean isCanceled() {
return delegate.isCanceled();
}
@Override
public Call<T> clone() {
return new CachedCall<>(delegate.clone());
}
@Override
public Request request() {
return delegate.request();
}
}
然後在我的ApiService,我用我的一些調用這個自定義實現,和一些其他爲例默認的:
public interface APIService {
@GET("categories")
Call<List<Categorie>> categories(@Query("tag") String tag);
@GET("categories/{categorie}/quotes")
CachedCall<List<Gif>> gifs(@Path("categorie") String categorie);
當與方法自定義一個被調用,我碰到了:
Caused by: java.lang.IllegalArgumentException: Could not locate call adapter for CustomClass.
Tried:
* retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
* retrofit2.ExecutorCallAdapterFactory
at retrofit2.Retrofit.nextCallAdapter(Retrofit.java:237)
at retrofit2.Retrofit.callAdapter(Retrofit.java:201)
at retrofit2.ServiceMethod$Builder.createCallAdapter(ServiceMethod.java:232)
... 21 more
是否需要註冊我的自定義實現w ith在某處改造?
你使用RxJava2嗎? – Raghunandan
Nop,我不知道。我看到了一些答案,添加「.addCallAdapterFactory(RxJavaCallAdapterFactory.create())」來解決這個問題,但它沒有奏效。 – Dimillian
你可以發佈你的翻新服務電話嗎? – Raghunandan