MarcusH
MarcusH

Reputation: 1703

Why doesn't this simple RxJava statement run?

I am learning RxJava from http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/

Copying and pasting his hello world example gives a compilation error saying the method does not override one in the superclass. So I used the same example, but had Eclipse generate the "call" method:

Observable<String> myObservable = Observable.create(
            new Observable.OnSubscribe<String>() {

                public void call(Subscriber<? super String> arg0) {
                    // TODO Auto-generated method stub
                    System.out.println("Hi");

                    arg0.onNext("Hello, world!");
                    arg0.onCompleted();
                }
            }
        );

Running the above code does not print anything, verifying that the call method is never invoked.

My build.gradle file:

apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.5
version = '1.0'
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version':     
version
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    testCompile group: 'junit', name: 'junit', version: '4.+'
    compile 'io.reactivex:rxjava:1.0.0'
}

test {
    systemProperties 'property': 'value'
}

uploadArchives {
    repositories {
       flatDir {
           dirs 'repos'
       }
    }
}

If someone could link a great, intuitive tutorial on rxjava or rxandroid that would be appreciated too.

Upvotes: 1

Views: 500

Answers (1)

zsxwing
zsxwing

Reputation: 20836

It outputted nothing because you didn't call subscribe. Read the post again and you will find the following code:

myObservable.subscribe(mySubscriber);
// Outputs "Hello, world!"

Upvotes: 2

Related Questions