title: java.lang.NullPointerException, why?
body: <p>In my android app which uses google cloud endpoints as a scalable backend solution, I am getting a NullPointerException when making a call to get the users friends in the exposed endpoints api.</p>
  
  <p>Initially, in my fragment, FriendFragment, I make the call to the async task class;</p>
  
  <pre><code>new EndpointTask.GetFriends(mUserId, FriendFragment.this).execute();
  </code></pre>
  
  <p>Then, this async task class makes a call to the endpoints api method named getFriends;</p>
  
  <pre><code>return mApi.getFriends(mUserId).execute().getItems();
  </code></pre>
  
  <p>This calls this method which functions as expected in the api explorer;</p>
  
  <pre><code>@ApiMethod(name = "getFriends", path = "friends", httpMethod = ApiMethod.HttpMethod.GET)
      public List&lt;Profile&gt; getFriends(@Named("userId") String userId) {
          Profile profile = ofy().load().key(Key.create(Profile.class, userId)).now();
          if (profile != null) {
              List&lt;Profile&gt; friends = new ArrayList&lt;&gt;(0);
              for (String friendId : profile.getFriendIds()) {
                  Profile friend = ofy().load().key(Key.create(Profile.class, friendId)).now();
                  friends.add(friend);
              }
              return friends;
          }
          return null;
      }
  </code></pre>
  
  <p>The returned List is sent back to the fragment via an interface which it implements;</p>
  
  <pre><code>// The interface
  public interface OnFetchedFriends {
      void sendFriends(List&lt;Profile&gt; friends);
  }
  
  @Override
  protected void onPostExecute(List&lt;Profile&gt; friends) {
      super.onPostExecute(friends);
      mListener.sendFriends(friends);
  }
  
  // In the fragment
  @Override
  public void sendFriends(List&lt;Profile&gt; friends) {
      mFriends.clear();
      mFriends.addAll(friends);
      mAdapter.notifyDataSetChanged();
  }
  </code></pre>
  
  <p>This data is then passed into the adapter and should be displayed onscreen in a recycler view;</p>
  
  <pre><code>RecyclerView requestRecyclerView = (RecyclerView) view.findViewById(R.id.friends_recycler_view);
  requestRecyclerView.setHasFixedSize(true);
  LinearLayoutManager mLayoutManager = new LinearLayoutManager(getContext());
  mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
  requestRecyclerView.setLayoutManager(mLayoutManager);
  
  mAdapter = new FriendAdapter(mFriends);
  requestRecyclerView.setAdapter(mAdapter);
  </code></pre>
  
  <p>Here is the stack trace:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.hb.backend.birthpayApi.model.ProfileCollection.getItems()' on a null object reference
      at com.hb.birthpay.utils.EndpointTask$GetFriends.doInBackground(EndpointTask.java:101)
      at com.hb.birthpay.utils.EndpointTask$GetFriends.doInBackground(EndpointTask.java:67)
  </code></pre>
  
  <p>Why is a java.lang.NullPointerException occurring?</p>