I want to use RxAndroid and RxJava in my project. But as shown in the below code, in getAnimalsObserver() method, the following line:
return new Observer<String>
is underscored with a red line saying: //class must be either declared abstract or implement abstract method please let me know how to fix that error.
code: import rx.Observable; import rx.Observer; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers;
//class must be either declared abstract or implement abstract method
private Observer<String> getAnimalsObserver() {
return new Observer<String>() {
@Override
public void onSubscribe(Disposable d) {
Log.d(TAG, "onSubscribe");
}
@Override
public void onNext(String s) {
Log.d(TAG, "Name: " + s);
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.d(TAG, "All items are emitted!");
}
};
}
This is the
Observer
interface you are implementing:As you can see, it's
onCompleted()
notonComplete()
.Tip: With the cursor inside the body of your implementation class, press
Ctrl+I
, Android Studio IDE will show dialog with available class members to implement.