title: Android Retrofit error - Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
body: <p>I am trying to get <code>JSON</code> data via http using Retrofit for Android. I am getting the following error:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
  </code></pre>
  
  <p>I am trying to retrieve the businessName and city from the <code>JSON</code> result.<br/> (searchListings->searchListing->businessName &amp; searchListings->searchListing->city)</p>
  
  <p>Here are my classes.</p>
  
  <p>Client:</p>
  
  <pre><code>public class RestClient {
  
      public static final String BASE_URL2 = "http://pubapi.yp.com/";
      private static Retrofit retrofit = null;
  
      public static Retrofit getClient() {
          if (retrofit==null) {
              retrofit = new Retrofit.Builder()
                      .baseUrl(BASE_URL2)
                      .addConverterFactory(GsonConverterFactory.create())
                      .build();
          }
          return retrofit;
      }
  }
  </code></pre>
  
  <p>Interface:</p>
  
  <pre><code>public interface SearchAPIService {
      @GET("/search-api/search/devapi/search?searchloc=30043&amp;term=barbers&amp;format=json&amp;sort=distance&amp;radius=1&amp;listingcount=20&amp;key=gmj3x7mhsh")
      public
          //End Url
      Call&lt;SearchList&gt; fetchShopsList();
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public class Search {
  
      String businessName;
      String city;
  
      public String getName() {
          return businessName;
      }
  
      public String getCity() {
          return city;
      }
  }
  </code></pre>
  
  <p>Model to hold list:</p>
  
  <pre><code>public class SearchList {
  
      List&lt;Search&gt; searchListing;
  
      public List&lt;Search&gt; getShops() {
          return searchListing;
      }
  }
  </code></pre>
  
  <p>MainActivity to print results</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private static final String TAG = MainActivity.class.getSimpleName();
      SearchAPIService apiSearch;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          apiSearch = RestClient.getClient().create(SearchAPIService.class);
          fetchSearchList();
      }
  
      private void fetchSearchList() {
          Call&lt;SearchList&gt; call = apiSearch.fetchShopsList();
          call.enqueue(new Callback&lt;SearchList&gt;() {
              @Override
              public void onResponse(Call&lt;SearchList&gt; call, Response&lt;SearchList&gt; response) {
                  Log.d(TAG, "Total number fetched : " + response.body().getShops().size());
  
                  for(Search search : response.body().getShops()){
                      //Print out Business Name and City in log
                      Log.d(TAG, "Name: " + search.getName());
                      Log.d(TAG, "City: " + search.getCity());
                  }
  
              }
  
  
              @Override
              public void onFailure(Call&lt;SearchList&gt; call, Throwable t) {
                  Log.e(TAG, "Got error : " + t.getLocalizedMessage());
              }
          });
      }
  }
  </code></pre>