2014-12-19 113 views
1

我从http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/这个简单的RxJava语句为什么不运行?

复制学习RxJava和粘贴自己的Hello World的例子给出了一个编译错误说的方法不会覆盖一个超类。所以,我用同样的例子,但有Eclipse中产生的“通话”的方法:

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(); 
       } 
      } 
     ); 

运行上面的代码不显示任何信息,验证调用方法不会被调用。

我的build.gradle文件:

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' 
     } 
    } 
} 

如果有人能链接rxjava或rxandroid一个伟大的,直观的教程,将太感激。

回答

2

它不输出任何内容,因为您没有拨打subscribe。再次阅读帖子,你会发现下面的代码:

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

谢谢。如果我将@Override注释添加到任何回调中,我注意到eclipse显示编译时错误。 IDE不会将回调识别为匿名类的超类中的方法。 – MarcusH 2014-12-21 03:22:48

相关问题