gabhor
gabhor

Reputation: 789

java.lang.IllegalArgumentException: Could not locate call adapter for rx.Single<com.squareup.okhttp.ResponseBody>

I use RxJava1 and Retrofit2 in my project. Around 10% of my users get the following error:

Caused by java.lang.IllegalArgumentException: Could not locate call                 
adapter for rx.Single<com.squareup.okhttp.ResponseBody>.
 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)
       at 
retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:160)
       at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
       at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
       at java.lang.reflect.Proxy.invoke(Proxy.java:913)
...

The related code snippets are the following:

import rx.Single

val retrofit = Retrofit.Builder()
        .addConverterFactory(GsonConverterFactory.create())
        .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
        .baseUrl(BuildConfig.API_BASE_URL)
        .build()

@FormUrlEncoded
@POST("/example")
fun exampleFun(@Field("param") param1: String): Single<ResponseBody>

implementation 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'

I've already found similar questions but this is not the same problem.

Upvotes: 1

Views: 2154

Answers (1)

gabhor
gabhor

Reputation: 789

Finally I changed Single to Observable and now it works fine. But if someone knows a better solution, please let me know!

Upvotes: 1

Related Questions