Cannot Resolve method subscribe(anonymous org.reactivestreams.Subscriber 已解决

使用Rxjava2 出现错误:
Cannot Resolve method 'subscribe(anonymous org.reactivestreams.Subscriber<Model Name>

原代码:

 subscribe(new Subscriber(){ 

        @Override 
        public void onSubscribe(Subscription s) { 

        } 

        @Override 
        public void onNext(UserResponse userResponse) { 

        } 

        @Override 
        public void onError(Throwable t) { 

        } 

        @Override 
        public void onComplete() { 

        } 
       }); 

使用时参考的是Rxjava第一版,Subscriber用于订阅Observer
而第二版:Subscriber订阅一个Flowable,而Observable使用Observer。所以修改如下:

.subscribe(new Observer() { 
    @Override 
    public void onSubscribe(Disposable d) {} 

    @Override 
    public void onNext(Void orderValues) {} 

    @Override 
    public void onError(Throwable e) {} 

    @Override 
    public void onComplete() {} 
}); 

你可能感兴趣的:(Android,retrofit,Rxjava,android,react,native,android,studio)