title: AsyncTask doInBackground returning a nullpointerexception when internet connection is failed
body: <p>After make connection check by DomenK i've got next errors and my try catch block look like this:</p>
  
  <pre><code>try
              {
                 if (isNetworkAvailable(getApplicationContext()))
                    updateJSONdata();
              }
              catch (Exception ex)
              {
                 Toast.makeText(getApplicationContext(), "shit happens", Toast.LENGTH_SHORT).show();
                 finish();
              }
  
  01-06 19:24:41.221: E/AndroidRuntime(2174): FATAL EXCEPTION: main
  01-06 19:24:41.221: E/AndroidRuntime(2174): java.lang.NullPointerException
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at com.flex.sklepik.ReadComments.updateList(ReadComments.java:253)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at com.flex.sklepik.ReadComments$LoadComments.onPostExecute(ReadComments.java:317)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at com.flex.sklepik.ReadComments$LoadComments.onPostExecute(ReadComments.java:1)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at android.os.AsyncTask.finish(AsyncTask.java:417)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at android.os.AsyncTask.access$300(AsyncTask.java:127)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at android.os.Handler.dispatchMessage(Handler.java:99)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at android.os.Looper.loop(Looper.java:130)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at android.app.ActivityThread.main(ActivityThread.java:3701)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at java.lang.reflect.Method.invokeNative(Native Method)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at java.lang.reflect.Method.invoke(Method.java:507)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
  01-06 19:24:41.221: E/AndroidRuntime(2174):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>My app works very well but when internet connection is broke while Async is working my app dies. Below is my logcat and async code block. Maybe somebody can help my how to make try catch block or something that will detect internet connection problem, cancel next job, auto return to first activity and toast simple info with internet connection problem.</p>
  
  <p>AsyncTask</p>
  
  <pre><code>public class LoadComments extends AsyncTask&lt;Void, Void, Boolean&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(ReadComments.this);
              pDialog.setMessage("ŁADUJĘ LISTĘ SKLEPÓW");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(true);
              pDialog.show();
              wczytajMape();
              idzDoPolozenia(52.249665, 21.012511, 10);
          }
  
          @Override
          protected Boolean doInBackground(Void... arg0) {
              // we will develop this method in version 2
  
                  updateJSONdata();
  
  
              return null;
  
          }
  
          @Override
          protected void onPostExecute(Boolean result) {
              super.onPostExecute(result);
              pDialog.dismiss();
              // we will develop this method in version 2
              updateList();
              ustawMape();
              mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
          }
  
      }
  </code></pre>
  
  <p>StackTrace:</p>
  
  <pre><code>01-06 18:52:14.583: E/AndroidRuntime(32139): FATAL EXCEPTION: AsyncTask #1
  01-06 18:52:14.583: E/AndroidRuntime(32139): java.lang.RuntimeException: An error occured while executing doInBackground()
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at java.lang.Thread.run(Thread.java:1019)
  01-06 18:52:14.583: E/AndroidRuntime(32139): Caused by: java.lang.NullPointerException
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at com.flex.sklepik.ReadComments.updateJSONdata(ReadComments.java:195)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at com.flex.sklepik.ReadComments$LoadComments.doInBackground(ReadComments.java:294)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at com.flex.sklepik.ReadComments$LoadComments.doInBackground(ReadComments.java:1)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  01-06 18:52:14.583: E/AndroidRuntime(32139):    ... 4 more
  01-06 18:52:14.793: W/ResourceType(32139): getEntry failing because entryIndex 13 is beyond type entryCount 2
  01-06 18:52:14.793: W/ResourceType(32139): Failure getting entry for 0x7f0b000d (t=10 e=13) in package 0 (error -2147483647)
  01-06 18:52:14.793: E/GooglePlayServicesUtil(32139): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
  01-06 18:52:14.813: W/ResourceType(32139): getEntry failing because entryIndex 13 is beyond type entryCount 2
  01-06 18:52:14.823: W/ResourceType(32139): Failure getting entry for 0x7f0b000d (t=10 e=13) in package 0 (error -2147483647)
  01-06 18:52:14.823: E/GooglePlayServicesUtil(32139): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
  01-06 18:52:15.173: W/Ads(32139): There was a problem getting an ad response. ErrorCode: 2
  01-06 18:52:15.193: E/WindowManager(32139): Activity com.flex.sklepik.ReadComments has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2afc3688 that was originally added here
  01-06 18:52:15.193: E/WindowManager(32139): android.view.WindowLeaked: Activity com.flex.sklepik.ReadComments has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2afc3688 that was originally added here
  01-06 18:52:15.193: E/WindowManager(32139):     at android.view.ViewRoot.&lt;init&gt;(ViewRoot.java:267)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.app.Dialog.show(Dialog.java:241)
  01-06 18:52:15.193: E/WindowManager(32139):     at com.flex.sklepik.ReadComments$LoadComments.onPreExecute(ReadComments.java:285)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.os.AsyncTask.execute(AsyncTask.java:391)
  01-06 18:52:15.193: E/WindowManager(32139):     at com.flex.sklepik.ReadComments.onResume(ReadComments.java:147)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.app.Activity.performResume(Activity.java:3832)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2131)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2156)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.app.ActivityThread.access$1500(ActivityThread.java:121)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.os.Handler.dispatchMessage(Handler.java:99)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.os.Looper.loop(Looper.java:130)
  01-06 18:52:15.193: E/WindowManager(32139):     at android.app.ActivityThread.main(ActivityThread.java:3701)
  01-06 18:52:15.193: E/WindowManager(32139):     at java.lang.reflect.Method.invokeNative(Native Method)
  01-06 18:52:15.193: E/WindowManager(32139):     at java.lang.reflect.Method.invoke(Method.java:507)
  01-06 18:52:15.193: E/WindowManager(32139):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
  01-06 18:52:15.193: E/WindowManager(32139):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
  01-06 18:52:15.193: E/WindowManager(32139):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>