Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxAndroid in conjunction with RxJava 2 #348

Closed
programmerr47 opened this issue Nov 7, 2016 · 17 comments
Closed

RxAndroid in conjunction with RxJava 2 #348

programmerr47 opened this issue Nov 7, 2016 · 17 comments

Comments

@programmerr47
Copy link

Hello.

Recently rxJava 2 has been released.
So currently when I try to use rxAndroid 1.2.1 with rxJava 2.0.0:

observable
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())

I'm getting an error:

observeOn(io.reactivex.Schedulers) in Observable cannot be applied to (rx.Scheduler)

I suppose it is because in rxJava 2 Schedulers was moved from rx package to io.reactivex package.

My question is, how I can use rxAndroid in conjunction with rxJava 2?

Thank you.

@xubuhang
Copy link

xubuhang commented Nov 9, 2016

@programmerr47 @JakeWharton @mttkay Hello,How do I solve this problem ?

@programmerr47
Copy link
Author

@xubuhang Hi. Simple: compile 'io.reactivex.rxjava2:rxandroid:2.0.0'
It was my mistake that I didn't search a little bit before posting this issue

@viethoa
Copy link

viethoa commented Jan 22, 2017

Still have the same problem with io.reactivex.rxjava2:rxandroid:2.0.0. This is not solve the error observeOn(io.reactivex.Schedulers) in Observable cannot be applied to (rx.Scheduler)

@dimsuz
Copy link

dimsuz commented Jan 22, 2017

@viethoa You have a wrong import - rx.Scheduler is a scheduler from rxjava1, you need to import one from io.reactivex

@replyashu
Copy link

replyashu commented Feb 11, 2017

@programmerr47 @JakeWharton @mttkay
Still getting error io.reactivex.rxjava2:rxandroid:2.0.1. This does not solve the error observeOn(io.reactivex.Schedulers) in Observable cannot be applied to (rx.Scheduler)

@JakeWharton
Copy link
Member

JakeWharton commented Feb 11, 2017 via email

@replyashu
Copy link

@JakeWharton :
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;

These are my imports

@JakeWharton
Copy link
Member

JakeWharton commented Feb 11, 2017 via email

@buddhasaikia
Copy link

Your import for Observable should be import io.reactivex.Observable; not import rx.Observable;

@replyashu
Copy link

@JakeWharton apology, it was import in another file, which was being reflected here. Thanks for the prompt reply. And hats off to your contribution in RxJava and other libraries

@ku4irka
Copy link

ku4irka commented Mar 13, 2017

@JakeWharton @bs2015 @dimsuz
If I choose to import io.reactivex.Observable; then I have a problem with Subscription
image

@akarnokd
Copy link
Member

@ku4irka In 2.x, the Observer requires Disposable and Disposables is the utility class to create some default instances.

@ku4irka
Copy link

ku4irka commented Mar 13, 2017

@akarnokd please can show the example code, because i do not fully can understand you

@akarnokd
Copy link
Member

import io.reactivex.*;
import io.reactivex.disposables.*;

Disposable disposable = Disposables.empty();

disposable = io.reactivex.Observable.just(1).subscribeWith(new DisposableObserver<Integer>() {
    // ...
});

https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#subscriber

@ku4irka
Copy link

ku4irka commented Mar 13, 2017

@akarnokd Thanks for the advice
have a good day :)

@trinadhkoya
Copy link

re check the import !! it should be as @replyashu said.

@mastermj94
Copy link

mastermj94 commented Jan 6, 2019

i had this problem too and my mistake , i was using wrong imports for rxjava2 so i changed my imports to:
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
i hope this can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests