Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No Instance of type variable R exist so that Observable conforms to Observable" Error when updating to RxJava2

I am trying to make a call to API using retrofit and rxJava. The code below seems to work well when using RxJava 1, but once I updated to RxJava 2 I am getting this error:

Error :

No Instance of type variable R exist so that Observable conforms to Observable

Api

Observable<HttpResult<List<Article>>> getList(@Query("key")String key);

Api request done here, and this is where I get this error inside .map operator

Observable cache=providers.getList().map(new HttpRsltFunc<List<Article>>());

Result class model :

private  class HttpRsltFunc<T> implements Func1<HttpResult<T>, T> {
       @Override
       public T call(HttpResult<T> httpResult) {   
           return httpResult.getData();
       }
   }

Edit :

When importing rx.Observable instead of io.reactivex.Observable the code works just fine.

Thank you

like image 300
Mohamed ALOUANE Avatar asked Dec 06 '16 16:12

Mohamed ALOUANE


1 Answers

This is happening because rxjava2 migrated to their own functional interfaces, so you need to implement different interface instead of Func1.

And don't forget to update your retrofit adapter to rxjava2 version: compile 'com.squareup.retrofit2:adapter-rxjava2:latest.version'

like image 122
Alexander Perfilyev Avatar answered Oct 30 '22 23:10

Alexander Perfilyev