title: Using Call Enqueue function in Retrofit
body: <p>I am using <code>Retrofit-2.0.0</code> for my app. Now every tutorial on Retrofit I found on web is based on earlier <code>Retrofit</code> and there was no <code>Call&lt;T&gt;</code> interface there. This is the first time I am using Retrofit and I am repeatedly getting <code>null object reference</code>. Here is my network model interface </p>
  
  <pre><code>public interface TMovieDBService {
      @GET("/movie")
      Call&lt;MovieResponse&gt; getMovieResponse(@Query("sort_by") String sortKey,
                               @Query("api_key") String apiKey);
  }
  </code></pre>
  
  <p>And this is my <code>updateMovies()</code> function which updates the list of movies. </p>
  
  <pre><code>void updateMovies() {
      Retrofit retrofit = new Retrofit.Builder()
              .baseUrl("http://api.themoviedb.org/3/discover")
              .addConverterFactory(GsonConverterFactory.create())
              .build();
  
      String sortKey = "popularity.desc";
      TMovieDBService service = retrofit.create(TMovieDBService.class);
  
      Call&lt;MovieResponse&gt; call = service.getMovieResponse(sortKey, ApiKey.API_KEY);
  
      call.enqueue(new Callback&lt;MovieResponse&gt;() {
          @Override
          public void onResponse(Response&lt;MovieResponse&gt; response) {
              Log.d(LOG_TAG, "Reached this place");
              if (!response.isSuccess()) {
                  Log.d(LOG_TAG, "No Success");
              }
              mMovieList = response.body().getMovies();  // &lt;- response is null here
              // Log.d(LOG_TAG, "Couldn't not reach this place");
              mMovieAdapter.notifyDataSetChanged();
              Log.d(LOG_TAG, "Response returned by website is : " + response.code());
          }
  
          @Override
          public void onFailure(Throwable t) {
              // Toast for the moment
              // Appropriate error handling code should be present here
              Toast.makeText(getActivity(), "Failed !", Toast.LENGTH_LONG).show();
          }
      });
  }
  </code></pre>
  
  <p>I don't know what to implement in the enqueue function. Very little is given on the retrofit website on how to use the callback. Assume all the other code is working fine. Here <code>MovieResponse</code> object is returned by the movieDB API which contains an array of <code>Movie</code>s and some extra information. I am implementing it in such a way so that once I get the response in <code>MovieResponse</code> from there I can extract using the <code>getMovies()</code> which will return a list of movies. </p>
  
  <p>When I run I simply get <code>null object reference</code> because <code>response</code> is null. I tried to search for tutorials on using new <code>Retrofit-2.0.0</code> especially on using enqueue function but I am out of luck. Plus one more question where should the <code>updateMovies()</code> be called. Can I call it directly in the mainactivity. Does retrofit automatically run the network call on background thread ? </p>