无法为 retrofit2.Response<...> 创建调用适配器

Unable to create call adapter for retrofit2.Response<...>

我的Api:

@GET("/cinema/notShownMovies")
fun getNotShownMovies(
   @Query("token") token: String
): Response<GetMovieResponse>

尝试调用 API 时出现异常:

java.lang.IllegalArgumentException: Unable to create call adapter for retrofit2.Response<...data.GetMovieResponse> for method InstanceApi.getNotShownMovies Unable to create call adapter for retrofit2.Response<...data.GetMovieResponse> for method InstanceApi.getNotShownMovies

我不知道从哪里开始。所有其他 API 调用都可以正常工作,这也在同一个 API class 中定义。可能是模型错误?

如果使用 coroutines,只需添加 suspend 修饰符。这将解决问题。

否则您的问题可能是因为在实例化您的 Retrofit 对象时没有添加调用适配器。 例如,对于 RxJava2,您可以通过在构建时添加此行来包含调用适配器。

.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))