title: Error in Intent Service in Android
body: <p>I am trying to fetch some for Location Address using IntentService but ended up with error leading to app crash. Please help me.</p>
  
  <p>Here is the Stacktrace:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.ResultReceiver.send(int, android.os.Bundle)' on a null object reference
          at com.example.ajender.sample2.FetchAddressIntentService.deliverResultToReceiver(FetchAddressIntentService.java:91)
          at com.example.ajender.sample2.FetchAddressIntentService.onHandleIntent(FetchAddressIntentService.java:81)
          at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.os.HandlerThread.run(HandlerThread.java:61)
  </code></pre>
  
  <p>Here is <code>FetchAddressIntentService</code>:</p>
  
  <pre><code>public class FetchAddressIntentService extends IntentService {
  private static String TAG="Fetch-address-Service";
  protected ResultReceiver mReceiver;
  
  /**
   * Creates an IntentService.  Invoked by your subclass's constructor.
   *
   * @param name Used to name the worker thread, important only for debugging.
   */
  public FetchAddressIntentService(String name) {
      super(name);
  }
  public FetchAddressIntentService(){
      super("FetchAddressIntentService");
  }
  
  @Override
  protected void onHandleIntent(Intent intent) {
      String errorMessage = "";
      Geocoder geocoder = new Geocoder(this, Locale.getDefault());
      Location location = intent.getParcelableExtra(
              Constants.LOCATION_DATA_EXTRA);
      mReceiver=intent.getParcelableExtra(Constants.RECEIVER);
      Log.e(TAG,"1-----");
      List&lt;Address&gt; addresses = null;
  
      try {
          addresses = geocoder.getFromLocation(
                  location.getLatitude(),
                  location.getLongitude(),
                  // In this sample, get just a single address.
                  1);
      } catch (IOException ioException) {
          // Catch network or other I/O problems.
          errorMessage = "service_not_available";
          Log.e(TAG, errorMessage, ioException);
      } catch (IllegalArgumentException illegalArgumentException) {
          // Catch invalid latitude or longitude values.
          errorMessage = "invalid_lat_long_used";
          Log.e(TAG, errorMessage + ". " +
                  "Latitude = " + location.getLatitude() +
                  ", Longitude = " +
                  location.getLongitude(), illegalArgumentException);
      }
      // Handle case where no address was found.
      if (addresses == null || addresses.size()  == 0) {
          if (errorMessage.isEmpty()) {
              errorMessage = "no_address_found";
              Log.e(TAG, errorMessage);
          }
          deliverResultToReceiver(Constants.FAILURE_RESULT, errorMessage);
      } else {
          Address address = addresses.get(0);
          ArrayList&lt;String&gt; addressFragments = new ArrayList&lt;String&gt;();
  
          // Fetch the address lines using getAddressLine,
          // join them, and send them to the thread.
          for(int i = 0; i &lt; address.getMaxAddressLineIndex(); i++) {
              addressFragments.add(address.getAddressLine(i));
          }
          Log.i(TAG, "address_found");
          deliverResultToReceiver(Constants.SUCCESS_RESULT,
                  TextUtils.join(System.getProperty("line.separator"),
                          addressFragments));
      }
  
  }
  
  private void deliverResultToReceiver(int resultCode, String message) {
      Bundle bundle = new Bundle();
      bundle.putString(Constants.RESULT_DATA_KEY, message);
      Log.e(TAG, "2-----");
      mReceiver.send(resultCode, bundle);
      Log.e(TAG, "3-----");
  }
  </code></pre>
  
  <p>This service should have to send back bundle with Result Receiver and result code but not happening....</p>