Error in request Retrofit + RxJava

0

I am starting with RxJava and I try to merge it with requests made with retrofit (which work correctly), but I have run into an error, which I hope can help me. I share fragments of my code:
My dependencies:

compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.0'

This is the interface:

public interface Calls {
    String KEY = "AIzaSyA7m5YQp_OQXvZ7DzylErwubKq7BhIVUcs";
    String BASE_URL="https://maps.googleapis.com/";

    @GET("maps/api/place/nearbysearch/json?radius=2000&type=bank&key="+KEY)
    //Call<Basic<ArrayList<Place>>> getSities(@Query("location") String location);       //Utilizada con Retrofit
    Observable<Basic<ArrayList<Place>>> getSities(@Query("location") String location);//Utilizada con RXJava
}

RetrofitClient Class

public class RetrofitClient {
private static Retrofit retrofit = null;

public static Retrofit getClient(String baseUrl) {
    if (retrofit==null) {
        retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}
}

and with this I intend to obtain the data:

RetrofitClient.getClient(Calls.BASE_URL).create(Calls.class)
            .getSities(LATITUDE+","+LONGITUDE)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(places -> {                   
                rvPlacesList.setHasFixedSize(true);
                PlaceAdapterRV adapterRV = new PlaceAdapterRV(places.getResults());
                rvPlacesList.setAdapter(adapterRV);
                rvPlacesList.setLayoutManager(new LinearLayoutManager(getApplicationContext(),LinearLayoutManager.VERTICAL,false));
            });

And this is the error that throws me:

Any suggestions are welcome.

    
asked by dámazo 15.07.2017 в 02:24
source

1 answer

0

At the end of the term error being something so simple ... it was including dependencies of the rxjava1 adapter of retrofit instead of the rxjava2 adapter. It was enough to modify the dependency and in turn update the version from 2.1.0 to 2.3.0.
Before:

compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'

After:

compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'

It is necessary to optimize the handling of the response, but the code already works.

    
answered by 24.07.2017 / 05:54
source