as i am new to RxJava
trying to run following code but its showing me
Cannot resolve symbol `Obserable.onSubscribe`
code is as follow
Observable<String> fetchFromGoogle = Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
try {
}catch(Exception e){
subscriber.onError(e); // In case there are network errors
}
}
});
have added following entries in gradle
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.8'
for java 8 compatibility
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
From the comments:
You are depending on RxJava 2 but the code example is for RxJava 1. There is no Observable.OnSubscribe in v2 and you are not supposed to call create(OnSubscribe) either as it is deprecated for being unsafe.
If you wanted an RxJava 1 dependency:
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.3.4'
If you wanted RxJava 2 code:
io.reactivex.Observable<String> fetchFromGoogle = io.reactivex.Observable.create(
new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> emitter) {
try {
} catch(Exception e) {
emitter.onError(e); // In case there are network errors
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With