Hot questions for Handling OnErrorNotImplementedException in RxJava

Top 10 Java Open Source / RxJava / Handling OnErrorNotImplementedException

How to handle onError inside RxJava. I am getting "OnErrorNotImplementedException"

Question: In my app I am using ReactiveLocationProvider library. I subscribe for updates in the onCreate method. It works fine when the device is online but if I switch my wifi off and wait for the next background location updates the device OnErrorNotImplementedException. This is the log:

 java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add `onError` handling.
     at android.os.Handler.handleCallback(
Caused by: rx.exceptions.OnErrorNotImplementedException: Timed out waiting for response from server
     at rx.Observable$27.onError(
     at rx.observers.SafeSubscriber._onError(
     at rx.observers.SafeSubscriber.onError(
Caused by: Timed out waiting for response from server
     at android.location.Geocoder.getFromLocation(

MainActivity code:

public class MainActivity extends AppCompatActivity {
    ReactiveLocationProvider locationProvider;
Observable<List<Address>> reverseGeocodeObservable;

protected void onCreate(Bundle savedInstanceState) {
    //-----------MY CODE STARTS HERE-----------------
    //check if the user previously has seen the whats new message...
    sharedPref = getPreferences(Context.MODE_PRIVATE);
    editor = sharedPref.edit();
    if (sharedPref.getInt(getString(R.string.saved_if_whats_new_seen), 1) != 0){
        WhatsNewDialogCreator dialogCreator = new WhatsNewDialogCreator(this, sharedPref);;

    request = LocationRequest.create()
            .setFastestInterval(1 * 60 * 1000)
            .setInterval(60 * 60 * 1000);
    locationProvider = new ReactiveLocationProvider(this);
    //subscribe for background location updates...
    if(isNetworkAvailable()) {

    if(isFirstTimeLaunchingTheApp) {
        Log.d(TAG, "onCreate getLocation");

private void startBackgroundUpdates() {
    subscription = locationProvider.getUpdatedLocation(request)
            .subscribe(new Action1<Location>() {
                public void call(Location location) {
                    Log.d(TAG, "Getting Background updates...");
                    MainActivity.this.latitude = location.getLatitude();
                    MainActivity.this.longitude = location.getLongitude();

                    reverseGeocodeObservable = locationProvider
                            .getReverseGeocodeObservable(location.getLatitude(), location.getLongitude(), 1);


protected void onPause() {
    * check if onCreate there was no internet, thus = subscription == null...
    * start the background updates onPause if there is internet
    if (subscription == null && isNetworkAvailable()){
        Log.d(TAG,"startBackgroundUpdates on Pause...");

Answer: There is an error happening when you are trying to geocode the location.

Caused by: Timed out waiting for response from server at android.location.Geocoder.getFromLocation(

When you call subscribe with one Action1 as a parameter it only handles calls to onNext and if an error happens the app will crash.

You need to subscribe with:

subscribe(new Subscriber<Location>() {
    public void onNext(Location location) { /*Handle the location updates*/ }

    public void onCompleted() { }

    public void onError(Throwable e) { }