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.