title: How to do check if ArrayList object
body: <p>I am making a retrofit POST request using Paging library. 
  When the first page is loaded the next page is automatically called. 
  But when it comes to the last page (assume page 5), it requests for page 6, then on response
  the app crash with error</p>
  
  <p><code>java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()'</code> on a null object reference</p>
  
  <p>when it queries for page 6, from my LogCat, an HTTP response is OK with Content length 0. But when i do checking it crashes</p>
  
  <pre><code>        //...code
          private final ReplaySubject&lt;Rating&gt; ratingReplaySubject;
  
          //...code
          @Override
          public void onResponse(Call&lt;ArrayList&lt;Rating&gt;&gt; call, Response&lt;ArrayList&lt;Rating&gt;&gt; response) {
              if (response.isSuccessful()) {
                  callback.onResult(response.body(), Integer.toString(page.get()+1));
                  mutableLiveData.postValue(NetworkState.LOADED);
  
                  //First i tried this,
                  //response.body().forEach(ratingReplaySubject::onNext);
  
                  //Then I tried this,
                  //ArrayList&lt;Rating&gt; ratingArrayList = new ArrayList&lt;&gt;();
                  //ratingArrayList = response.body();
                  //if(ratingArrayList == null &amp;&amp; !ratingArrayList.isEmpty()){
                  //    for(int i=0; i&lt;ratingArrayList.size(); i++){
                  //        ratingReplaySubject.onNext(ratingArrayList.get(i));
                  //    }
                  //}
  
              } else {
                  mutableLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, response.message()));
                  Log.e("API CALL", response.message());
              }
          }
  </code></pre>