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

让人想犯罪 __ 提交于 2020-12-12 12:19:19

问题


My Api:

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


@JsonClass(generateAdapter = true)
data class Movie(
    val id: Long,
    val name: String,
    val date: String,

    @field:Json(name = "trailer_link")
    val trailerLink: String?,

    @field:Json(name = "poster_link")
    val posterLink: String?,

    @field:Json(name = "booked_tickets")
    val bookedTickets: Int,

    @field:Json(name = "movie_year_id")
    val movieYearId: Int,

    @field:Json(name = "created_at")
    val createdAt: String,

    @field:Json(name = "updated_at")
    val updatedAt: String,

    @field:Json(name = "worker_id")
    val workerId: Int?,

    @field:Json(name = "worker_name")
    val workerName: String?,

    @field:Json(name = "emergency_worker_id")
    val emergencyWorkerId: Int?,

    @field:Json(name = "emergency_worker_name")
    val emergencyWorkerName: String?,

    @field:Json(name = "booked_tickets_for_yourself")
    val bookedTicketsForYourself: Int,

    @field:Json(name = "view_movie")
    val viewMovie: ViewMovie
)

@JsonClass(generateAdapter = true)
data class ViewMovie(
    val href: String,
    val method: String
)

Exception when trying to call 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

I don't know where to start. All other API calls work fine which is also defined in the same API class. Maybe a model error?


回答1:


Just add suspend modifier if using coroutines. This will solve the problem.

Otherwise your issue is likely because there is no Call adapter added when instantiating your Retrofit object. For example, for RxJava2, you can include a call adapter by adding this line while building it.

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


来源:https://stackoverflow.com/questions/62464914/unable-to-create-call-adapter-for-retrofit2-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!