title: Attempt to invoke virtual method 'boolean java.util.ArrayList.isEmpty()' on a null object reference
body: <p>I am sending 2 kind of requests to the server once if the route is known then the data will be transmitted and  inserted into the table. The other one if the route is unknown then the server will be requested to provide the android app with the route  as long as there is available data to calculate the route otherwise route is 0.</p>
  
  <p>in <code>onPostExecute</code> I am checking wether the 'routeList' is not empty and not null though I am getting this error:</p>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>05-25 20:33:29.107: E/AndroidRuntime(1946): FATAL EXCEPTION: main
  05-25 20:33:29.107: E/AndroidRuntime(1946): Process: com.bustracker, PID: 1946
  05-25 20:33:29.107: E/AndroidRuntime(1946): java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Iterator java.util.ArrayList.iterator()' on a null object reference
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at com.bustracker.PostData$MyAsyncTask.onPostExecute(PostData.java:131)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at com.bustracker.PostData$MyAsyncTask.onPostExecute(PostData.java:1)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at android.os.AsyncTask.finish(AsyncTask.java:632)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at android.os.Handler.dispatchMessage(Handler.java:102)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at android.os.Looper.loop(Looper.java:145)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at android.app.ActivityThread.main(ActivityThread.java:5944)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at java.lang.reflect.Method.invoke(Native Method)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at java.lang.reflect.Method.invoke(Method.java:372)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
  05-25 20:33:29.107: E/AndroidRuntime(1946):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
  </code></pre>
  
  <p>onPostExecute():</p>
  
  <pre><code>ArrayList&lt;Integer&gt; routes = new ArrayList&lt;Integer&gt;();
  
  @Override
      protected void onPostExecute(Void result) {
          for (int item: routes){
              System.out.println("The output from the onPostExecute:  "+item);
          }
          // Intent with Conetxt of the Asyntask class and
          if (!routes.isEmpty() &amp;&amp; (routes != null)) {
              // if(routes !=null ){
              Intent intent = new Intent(mContext, MainActivity.class);
              intent.putIntegerArrayListExtra("stop_route", routes);
               intent.putExtra("stop_distance", distance);
              intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
              mContext.startActivity(intent);
  
          } else {
              Log.e("123", "Avoiding null pointer, the routes are null!!!");
  
          }
  
      }
  </code></pre>
  
  <p>onNewIntent():</p>
  
  <pre><code>@Override
  protected void onNewIntent(Intent intent) {
      // TODO Auto-generated method stub
      super.onNewIntent(intent);
  
      // getIntent() should always return the most recent
      setIntent(intent);
  
      Bundle extras = getIntent().getExtras();
      if (extras != null &amp;&amp; extras.containsKey("stop_route")) {
  
  
          double distance = extras.getDouble("stop_distance");
          System.out.println("The distance is: "+ distance);
  
          if (distance &lt;= 15) {
              stop_popup(extras);
  
          } else {
              final ArrayList&lt;Integer&gt; routeList = extras
                      .getIntegerArrayList("stop_route");
              route_number = routeList.get(0);
              System.out.println("The route number is: " + route_number);
          }
  
      } else {
          System.out.println("The intent is empty: ");
      }
  
  }
  </code></pre>