0

Im building a project using web3.

web3j.ethGetBalance("0x2910543af39aba0cd09dbb2d50200b3e800a63d2", latestBlock)
            .observable()
            .subscribeOn(rx.schedulers.Schedulers.io())
            //This needs to be on the main thread!
            //But i only have access to rx.schedulers not AndroidSchedulers.mainThread()
            .observeOn(rx.schedulers.Schedulers.io())
            .subscribe(block -> {
                ethereumTV.setText(block.getBalance() + "");
            }, error -> {
                error.printStackTrace();
            });

But web3 uses an older version of RxJava and i cant access the mainThread to observe on it (To update text views etc)

Any ideas?

TylerH
  • 20,799
  • 66
  • 75
  • 101
MrRed
  • 677
  • 1
  • 6
  • 21
  • 1
    `compile 'io.reactivex:rxandroid:1.2.1'` /* Because RxAndroid releases are few and far between, it is recommended you also */ /* explicitly depend on RxJava's latest version for bug fixes and new features.*/ `compile 'io.reactivex:rxjava:1.1.6'` – EpicPandaForce Sep 21 '17 at 15:03
  • this is my problem though -> 'observeOn(rx.Scheduler)' in 'rx.Observable' cannot be applied to '(io.reactivex.Scheduler)' – MrRed Sep 21 '17 at 15:06
  • if you can't add the `rxandroid` dependency to get `AndroidSchedulers` then you may have to build your own `Scheduler`. The main thread scheduler was just a wrapper around `handler.post(...)` anyway. – Jon Sep 21 '17 at 15:06
  • 1
    find out what version of rx you do have, and see if there was a corresponding rxandroid version with the same package names – Jon Sep 21 '17 at 15:08
  • You need to use `rx.android.AndroidSchedulers.mainThread()` – EpicPandaForce Sep 21 '17 at 15:20
  • Spot on as always EpicPandaForce. Coupled with the 'io.reactivex:rxandroid:1.2.1' import, rx.android.AndroidSchedulers.mainThread() works. Thank you so much dude. Want to add it as an answer so i can give you some marks? :) – MrRed Sep 21 '17 at 15:24

1 Answers1

1
compile 'io.reactivex:rxandroid:1.2.1' // <-- this is needed
compile 'io.reactivex:rxjava:1.1.6'

Then you can get

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

In which case do

rx.android.AndroidSchedulers.mainThread()
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428