title: RxJava2: "onSuccess called with null. Null values are generally not allowed in 2.x operators"
body: <p>I'm still learning RxJava so I'm having quite a tough time figuring this out...</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>The API is successful, however within <code>Single&lt;ResponseRegistration&gt; postRegisterAccount()</code> the error <code>onSuccess called with null. Null values are generally not allowed in 2.x operators</code> is generated.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>// in the View Layer
  addRxSubscription(mService.postRegistration()
          .subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread())
          .subscribe(success -&gt; {
                      if (success != null &amp;&amp; success) {
                          //successfully registered
                          updateNavigationDrawerMenu();
                      } else {
                          Log.e(TAG, "Failed to register !");
                      }
                  }, throwable -&gt; Log.e(TAG, "Failed to register !")
          ));
  break;
  
  
  // in the Service Layer, passes in the API parameters
  public Single&lt;Boolean&gt; postRegistration() {
      final String email = "test@email.com";
      final String pass = "testpass";
  
      PostRegistrationData registrationData = new PostRegistrationData(email, pass);
      Single&lt;ResponseRegistration&gt; singlePostRegistration = mApi.postRegisterAccount(registrationData);
  
      return Single.create(subscriber -&gt; singlePostRegistration.subscribeOn(Schedulers.io())
                  .observeOn(Schedulers.io())
                  .subscribe(registrationResponse -&gt; {
                      if (registrationResponse.userId != null) {
                          // Success, store the response and let UI know API was successful
                          storeRegistrationId(registrationResponse.userId);
                          if (!subscriber.isDisposed()) {
                              subscriber.onSuccess(true);
                          }
                      }
                      else {
                          // Failure, let UI know API was un-successful
                          if (!subscriber.isDisposed()) {
                              subscriber.onSuccess(false);
                          }
                      }
                  }, throwable -&gt; {
                      // Failure
                      if (!subscriber.isDisposed()) {
                          //
                          // Due to the failure in postRegisterAccount(), this code executes
                          //
                          subscriber.onError(throwable);
                      }
                  }));
  }
  
  
  // in the API layer - this strips the Response&lt;ResponseGeneric&lt;T&gt;&gt; wrapper from around the response data
  public Single&lt;ResponseRegistration&gt; postRegisterAccount(PostRegistrationData registrationData) {
      Single&lt;Response&lt;ResponseGeneric&lt;ResponseRegistration&gt;&gt;&gt; postRegistration = apiClient.postRegisterAccount(registrationData);
  
      return Single.create(subscriber -&gt; postRegistration.subscribeOn(Schedulers.io())
              .observeOn(Schedulers.io())
              .subscribe(response -&gt; {
                  if(response.isSuccessful() &amp;&amp; response.body() != null) {
                      //
                      // this part is successful - the response data is received
                      // HOWEVER java.lang.NullPointerException: onSuccess called with null. Null values are generally not allowed in 2.x operators and sources.
                      // subscriber = null
                      //
                      if (!subscriber.isDisposed()) subscriber.onSuccess(response.body().data);
                  }
              }, throwable -&gt; {
                  throwable.printStackTrace();
                  if(!subscriber.isDisposed()) subscriber.onError(throwable);
              }));
  }
  
  
  // Retrofit Interface
  @Headers({"Content-Type: application/json"})
  @POST(ServicesConstants.API_PREFIX + "registration/")
  Single&lt;Response&lt;ResponseGeneric&lt;ResponseRegistration&gt;&gt;&gt; postRegisterAccount(@Body PostRegistrationData postRegistrationData);
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>Why is <code>subscriber</code> null within <code>postRegisterAccount()</code> ?</p>