title: Retrofit 2: response.body() is null, but status code is 200
body: <p>I'm not sure why this is happening, I am trying to get data from:</p>
  
  <pre><code>https://api.stackexchange.com/2.2/questions?order=desc&amp;sort=creation&amp;site=stackoverflow&amp;tagged=android
  </code></pre>
  
  <p>Using the following code:</p>
  
  <pre><code>public interface StackOverflowAPI {
  
      @GET("/2.2/questions?order=desc&amp;sort=creation&amp;site=stackoverflow")
      Call&lt;StackQuestions&gt; loadQuestions(@Query("tagged") String tags);
  
  }
  </code></pre>
  
  <p>and classes:</p>
  
  <pre><code>public class StackQuestion {
  
      @SerializedName("title")
      private String title;
  
      @SerializedName("view_count")
      private int numViews;
  
      @SerializedName("is_answered")
      private boolean solved;
  
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  
      public int getNumViews() {
          return numViews;
      }
  
      public void setNumViews(int numViews) {
          this.numViews = numViews;
      }
  
      public boolean isSolved() {
          return solved;
      }
  
      public void setSolved(boolean solved) {
          this.solved = solved;
      }
  
  }
  
  
  public class StackQuestions {
      List&lt;StackQuestion&gt; questions;
  }
  </code></pre>
  
  <p>fragment:</p>
  
  <pre><code>public class AlphaFragment extends Fragment implements Callback&lt;StackQuestions&gt; {
  
      private StackOverflowAPI stackOverflowAPI;
  
      private EditText    etxtQuestionToSearch;
      private Button      btnSearchQuestion;
  
      private RecyclerView                mRecyclerView;
      private RecyclerView.Adapter        mStackQuestionsAdapter;
      private RecyclerView.LayoutManager  mLayoutManager;
  
      private ArrayList&lt;StackQuestion&gt; mStackQuestionsList;
  
      private final static String TAG = "AlphaFragment";
  
      public AlphaFragment() {}
  
  
      // ------------------------ FRAGMENT LIFECYCLE ------------------------ //
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          init();
      } // end : onCreate Method
  
      @Override
      public View onCreateView(LayoutInflater inflater,
                               ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_alpha, container, false);
  
          etxtQuestionToSearch = (EditText) view.findViewById(R.id.etxt_stack_topic);
          btnSearchQuestion = (Button) view.findViewById(R.id.button_stack_search);
          mRecyclerView = (RecyclerView) view.findViewById(R.id.rcvw_stackquestions_list);
  
          // Recycler View SETUP
          mLayoutManager = new LinearLayoutManager(getActivity());
          mRecyclerView.setLayoutManager(mLayoutManager);
          mRecyclerView.setItemAnimator(new DefaultItemAnimator());
  
          btnSearchQuestion.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  searchStackQuestion();
              } // end : onClick Method
          });
  
          return view;
      } // end : onCreateView Method
  
  
      // ------------------------- CALLBACK METHODS ------------------------- //
  
      @Override
      public void onResponse(Call&lt;StackQuestions&gt; call,
                             Response&lt;StackQuestions&gt; response) {
          if (response == null) {
              return;
          }
  
          List&lt;StackQuestion&gt; resultList = response.body().questions;
  
          // X:ERROR: .questions == NULL, so Toast appears
          if (resultList == null || resultList.isEmpty()) {
              Toast.makeText(getActivity(), "Results for the query are null/empty", Toast.LENGTH_LONG).show();
              return;
          }
  
          // Add resulting data from web service
          for (StackQuestion question : resultList) {
              mStackQuestionsList.add(question);
          }
  
          // Assign data to recycler view
          mStackQuestionsAdapter = new StackQuestionsAdapter(
              mStackQuestionsList,
              getActivity(),
              new RVTapListener() {
                  @Override
                  public void onItemClick(View v, int position) {
                      Toast.makeText(getActivity(), "Now clicked, but not implemented " + new Date(), Toast.LENGTH_SHORT).show();
                  } // end : onItemClick Method
              }
          );
          mRecyclerView.setAdapter(mStackQuestionsAdapter);
      } // end : onResponse Method
  
      @Override
      public void onFailure(Call&lt;StackQuestions&gt; call,
                            Throwable t) {
          Toast.makeText(getActivity(), t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
      } // end : onFailure Method
  
  
      // ------------------------- FRAGMENT METHODS ------------------------- //
  
      private void init() {
          Gson gson = new GsonBuilder()
              .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
              .create();
  
          HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
          interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
          OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
  
          Retrofit retrofit = new Retrofit.Builder()
              .baseUrl("https://api.stackexchange.com")
              .addConverterFactory(GsonConverterFactory.create(gson))
              .client(client)
              .build();
  
          stackOverflowAPI = retrofit.create(StackOverflowAPI.class);
      } // end : init Method
  
      private void searchStackQuestion() {
          mStackQuestionsList = new ArrayList&lt;&gt;();
  
          Call&lt;StackQuestions&gt; call = stackOverflowAPI.loadQuestions("android");
          call.enqueue(this);
      } // end : searchStackQuestion Method
  
  }    
  </code></pre>
  
  <p>Gradle dependencies:</p>
  
  <pre><code>compile 'com.google.code.gson:gson:2.7'
  compile 'com.android.support:design:24.0.0'
  compile 'com.squareup.retrofit2:retrofit:2.1.0'
  compile 'com.android.support:cardview-v7:24.0.0'
  compile 'com.android.support:appcompat-v7:24.0.0'
  compile 'com.android.support:recyclerview-v7:24.0.0'
  compile 'com.squareup.retrofit2:converter-gson:2.1.0'
  compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
  </code></pre>
  
  <p>After executing the code, I've got on logcat, the following:</p>
  
  <pre><code>D/OkHttp: &lt;-- 200 OK https://api.stackexchange.com/2.2/questions?order=desc&amp;sort=creation&amp;site=stackoverflow&amp;tagged=android (1136ms)
  D/OkHttp: Cache-Control: private
  D/OkHttp: Content-Type: application/json; charset=utf-8
  D/OkHttp: Access-Control-Allow-Origin: *
  D/OkHttp: Access-Control-Allow-Methods: GET, POST
  D/OkHttp: Access-Control-Allow-Credentials: false
  D/OkHttp: X-Content-Type-Options: nosniff
  D/OkHttp: Date: Tue, 28 Jun 2016 22:56:26 GMT
  D/OkHttp: {"items":[{"tags":["android"],"owner":{"reputation":1,"user_id"  ...
  D/OkHttp: er_id":1163471,"user_type":"registered","accept_rate":93,"profil ...
  D/OkHttp: e?type=large","display_name":"Vahid Zadeh","link":"http://stacko ...
  D/OkHttp: n_id":38086882,"link":"stackoverflow.com/questions/380868 ...
  D/OkHttp: ","animation-listener"],"owner":{"reputation":23,"user_id":43462 ...
  D/OkHttp: &lt;-- END HTTP (19295-byte body)
  </code></pre>
  
  <p>Everything is going fine, but i get NullPointerException in this part of the AlphaFragment:</p>
  
  <pre><code>List&lt;StackQuestion&gt; resultList = response.body().questions;
  
  // X:ERROR: .questions == NULL, so Toast appears
  if (resultList == null || resultList.isEmpty()) {
      Toast.makeText(getActivity(), "Results for the query are null/empty", Toast.LENGTH_LONG).show();
      return;
  }
  </code></pre>
  
  <p>What could be the problem? I've got <code>status code</code> <code>200</code>, and there is JSON information right there; but, after trying to retrieve it, <code>NPE</code> appears.</p>
  
  <p>Thanks in advance...</p>