IllegalArgumentException: Could not locate call adapter for rx.Observable RxJava, Retrofit2

后端 未结 5 1363
野的像风
野的像风 2020-12-15 03:39

I am getting the above error while calling the rest api. I am using both retrofit2 and RxJava.

ServiceFactory.java

public class ServiceFactory {
pu         


        
5条回答
  •  情歌与酒
    2020-12-15 04:20

    Be sure to add implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' or whatever version you are using to your dependencies, and then configure retrofit with that converter:

    Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(endpoint)
        .addConverterFactory(GsonConverterFactory.create())
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .build();
    

    Updated

    RxJavaCallAdapterFactory was renamed to RxJava2CallAdapterFactory. Changed the snipped above.

提交回复
热议问题