title: Android AsyncTask On Exit Exception
body: <p>I'm having problems with my Asynctask. Whenever I exit my app with my BACK button, it just caught an exception. Please take a look at my codes. Please help me to correct it. Thanks.</p>
  
  <p>AndroidFragment.java</p>
  
  <pre><code>    public class AndroidFragment extends SherlockListFragment  implements ActionBar.TabListener{
  
      private ProgressDialog pDialog;
      static final String URL = "https://dl.dropbox.com/s/86p8y5y2birua9n/test1.xml";
      // XML node keys
      static final String KEY_ITEM = "item"; // parent node
      static final String KEY_ID = "id";
      static final String KEY_NAME = "name";
      static final String KEY_COST = "cost";
      static final String KEY_DESC = "description";
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems;
      ListAdapter adapter;
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
          new loadListView().execute();   
      return super.onCreateView(inflater, container, savedInstanceState);
  
      }
  
      public class loadListView extends AsyncTask&lt;Integer, String, String&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
  
  
  
          }
  
          @Override
          protected String doInBackground(Integer... args) {
              // updating UI from Background Thread
              menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
  
              XMLParser parser = new XMLParser();
              String xml = parser.getXmlFromUrl(URL); // getting XML
              Document doc = parser.getDomElement(xml); // getting DOM element
  
              NodeList nl = doc.getElementsByTagName(KEY_ITEM);
              // looping through all item nodes &lt;item&gt;
              for (int i = 0; i &lt; nl.getLength(); i++) {
                  // creating new HashMap
                  HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                  Element e = (Element) nl.item(i);
                  // adding each child node to HashMap key =&gt; value
                  map.put(KEY_ID, parser.getValue(e, KEY_ID));
                  map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
                  map.put(KEY_COST, "Rs." + parser.getValue(e, KEY_COST));
                  map.put(KEY_DESC, parser.getValue(e, KEY_DESC));
  
                  // adding HashList to ArrayList
                  menuItems.add(map);
              }
  
  
  
  
                      return null;
                  }   
  
  
          @Override
          protected void onPostExecute(String args) {
  
  
              adapter = new SimpleAdapter(getActivity(), menuItems,
                      R.layout.list_item,
                      new String[] { KEY_NAME, KEY_DESC, KEY_COST }, new int[] {
                              R.id.name, R.id.desciption, R.id.cost });
  
  
              setListAdapter(adapter);
              //pDialog.dismiss();
              }
          }
  
       @Override
       public void onDestroy() {
           if (adapter  != null) {
           setListAdapter(null);
           }
           super.onDestroy();
       }
  
      @Override
      public void onTabSelected(Tab tab, FragmentTransaction ft) {
          ft.add(android.R.id.content, this);
  
          ft.attach(this);
      }
  
      @Override
      public void onTabUnselected(Tab tab, FragmentTransaction ft) {
          ft.detach(this);
      }
  
      @Override
      public void onTabReselected(Tab tab, FragmentTransaction ft) {
      }
  
  }
  </code></pre>
  
  <p>LOGCAT :</p>
  
  <pre><code>10-06 00:17:55.750: E/AndroidRuntime(8780): FATAL EXCEPTION: main
  10-06 00:17:55.750: E/AndroidRuntime(8780): java.lang.NullPointerException
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at android.widget.SimpleAdapter.&lt;init&gt;(SimpleAdapter.java:85)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at in.wptrafficanalyzer.actionbarsherlocknavtab.AndroidFragment$loadListView.onPostExecute(AndroidFragment.java:96)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at in.wptrafficanalyzer.actionbarsherlocknavtab.AndroidFragment$loadListView.onPostExecute(AndroidFragment.java:1)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at android.os.AsyncTask.finish(AsyncTask.java:602)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at android.os.AsyncTask.access$600(AsyncTask.java:156)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at android.os.Handler.dispatchMessage(Handler.java:99)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at android.os.Looper.loop(Looper.java:137)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at android.app.ActivityThread.main(ActivityThread.java:4512)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at java.lang.reflect.Method.invokeNative(Native Method)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at java.lang.reflect.Method.invoke(Method.java:511)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
  10-06 00:17:55.750: E/AndroidRuntime(8780):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>New LOGCAT :</p>
  
  <pre><code>10-06 00:49:26.094: E/AndroidRuntime(10780): FATAL EXCEPTION: main
  10-06 00:49:26.094: E/AndroidRuntime(10780): java.lang.NullPointerException
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at android.widget.SimpleAdapter.&lt;init&gt;(SimpleAdapter.java:85)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at in.wptrafficanalyzer.actionbarsherlocknavtab.AppleFragment$loadListView.onPostExecute(AppleFragment.java:97)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at in.wptrafficanalyzer.actionbarsherlocknavtab.AppleFragment$loadListView.onPostExecute(AppleFragment.java:1)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at android.os.AsyncTask.finish(AsyncTask.java:602)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at android.os.AsyncTask.access$600(AsyncTask.java:156)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at android.os.Handler.dispatchMessage(Handler.java:99)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at android.os.Looper.loop(Looper.java:137)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at android.app.ActivityThread.main(ActivityThread.java:4512)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at java.lang.reflect.Method.invokeNative(Native Method)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at java.lang.reflect.Method.invoke(Method.java:511)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
  10-06 00:49:26.094: E/AndroidRuntime(10780):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>