title: NullPointerException in AsyncTask OnPostExecute
body: <p>I am new to android.I am getting <code>data=null</code> when executing the onPostExecute which is correct.Now I just want to show a dialog that there is no data available.But I am getting the <code>NullPointerException</code>.</p>
  
  <pre><code>public class GetPreviousChatNewThread extends AsyncTask&lt;Void,Void,Void&gt; {
  
              ProgressDialog dialog;
              ArrayList&lt;HashMap&lt;String,String&gt;&gt; data;
  
              @Override
              protected  Void doInBackground(Void... void1) {
                  data=new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
                  data=HandleJSON.ParseJsonForUserAdminChats(sendHttpRequest(
                          "ReturnUserAdminChats",
                          "admin",
                          "You" ,
                          "a",
                          clientEmail,
                          UserAdminChatActivity.LastShowingChatDate));
                  return null;
              }
  
              @Override
               protected void onPostExecute(Void result) {
  
                  super.onPostExecute(result);
  
  
                  if(!data.isEmpty())      // &lt;-- error here
                  {   
                      adapter.InsertValuesAtTop(data);
                  }
                  else
                  {
                      Toast.makeText(getApplicationContext(), "No more data", Toast.LENGTH_LONG).show();
                  }
                  if(dialog.isShowing())
                   dialog.dismiss();
  
               }
  
              @Override
               protected void onPreExecute() {
                   dialog = ProgressDialog.show(UserAdminChatActivity.this, "", "Loading. Please wait...", true);
               }
  
          }
  </code></pre>
  
  <p>Here's my Logcat which shows the complete log of the process:</p>
  
  <pre><code>07-23 12:22:55.976: I/finalAnswer(25159): ["a@hotmail.com","c@hotmail.com","b@hotmail.com"]
  07-23 12:23:01.101: I/finalAnswer(25159): [{"username":"moji","chatText":"jingalala hu","chatDate":"4\\July\\2012"},{"username":"You","chatText":"bingalala hu","chatDate":"4\\July\\2012"},{"username":"moji","chatText":"jingalala hu","chatDate":"4\\July\\2012"}]
  07-23 12:23:01.101: I/GoTo Json(25159): [{"username":"moji","chatText":"jingalala hu","chatDate":"4\\July\\2012"},{"username":"You","chatText":"bingalala hu","chatDate":"4\\July\\2012"},{"username":"moji","chatText":"jingalala hu","chatDate":"4\\July\\2012"}]
  07-23 12:23:01.101: I/dateeeeeee(25159): 4\July\2012
  07-23 12:23:01.101: I/dateeeeeee(25159): 4\July\2012
  07-23 12:23:01.111: I/dateeeeeee(25159): 4\July\2012
  07-23 12:23:01.161: I/finalAnswer(25159): new"[]"
  07-23 12:23:02.603: I/finalAnswer(25159): []
  07-23 12:23:02.603: I/GoTo Json(25159): []
  07-23 12:23:02.613: D/AndroidRuntime(25159): Shutting down VM
  07-23 12:23:02.613: W/dalvikvm(25159): threadid=1: thread exiting with uncaught exception (group=0x4001d578)
  07-23 12:23:02.623: E/AndroidRuntime(25159): FATAL EXCEPTION: main
  07-23 12:23:02.623: E/AndroidRuntime(25159): java.lang.NullPointerException
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at com.app.ServerClient.UserAdminChatActivity$GetPreviousChatNewThread.onPostExecute(UserAdminChatActivity.java:197)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at com.app.ServerClient.UserAdminChatActivity$GetPreviousChatNewThread.onPostExecute(UserAdminChatActivity.java:1)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at android.os.AsyncTask.finish(AsyncTask.java:417)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at android.os.AsyncTask.access$300(AsyncTask.java:127)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at android.os.Handler.dispatchMessage(Handler.java:99)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at android.os.Looper.loop(Looper.java:138)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at android.app.ActivityThread.main(ActivityThread.java:3701)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at java.lang.reflect.Method.invokeNative(Native Method)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at java.lang.reflect.Method.invoke(Method.java:507)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
  07-23 12:23:02.623: E/AndroidRuntime(25159):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Edit:</p>
  
  <p>Heres the code for HandleJson:</p>
  
  <pre><code>public class HandleJSON {
  
  private static ArrayList&lt;HashMap&lt;String,String&gt;&gt; chat;
  static final String Key_username="username_key";
  static final String Key_email="email_key";
  static final String Key_messageText="messageText_key";
  static final String Key_messageDate="messageDate_key";
  static final String Key_messageCounts="messageCount_key";
  static boolean newObject;
  
  public static ArrayList&lt;HashMap&lt;String,String&gt;&gt;  ParseJsonForLatestChats(String jsonData)
  {
         try {
  
             if(HandleJSON.newObject)
             {
                 chat=new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
             }
             Log.i("jsonReturned",jsonData.toString());
             JSONArray jsonarr=new JSONArray(jsonData);
              for(int i=0;i&lt;jsonarr.length();i++)
              {   
                  HashMap&lt;String,String&gt; hashMap=new HashMap&lt;String,String&gt;();
  
                  hashMap.put(HandleJSON.Key_username, jsonarr.getJSONObject(i).getString("username"));
                  hashMap.put(HandleJSON.Key_email, jsonarr.getJSONObject(i).getString("email"));
                  hashMap.put(HandleJSON.Key_messageCounts, jsonarr.getJSONObject(i).getString("count"));
  
                  chat.add(hashMap);
  
              }
  
              return chat;
        }
        catch(JSONException e)
        {
            Log.e("JsonDek", e.getMessage());
            return null;
        }
  }
  
  public static ArrayList&lt;HashMap&lt;String,String&gt;&gt;  ParseJsonForUserAdminChats(String jsonData)
  {
  
         chat=new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
  
  try {
  
           JSONArray jsonarr=new JSONArray(jsonData);
           Log.i("GoTo Json",jsonData);
              UserAdminChatActivity.LastShowingChatDate=jsonarr.getJSONObject(0).getString("chatDate");
              for(int i=jsonarr.length()-1;i&gt;=0;i--)
              {   
                  HashMap&lt;String,String&gt; hashMap=new HashMap&lt;String,String&gt;();
  
                  hashMap.put(HandleJSON.Key_username, jsonarr.getJSONObject(i).getString("username"));
                  hashMap.put(HandleJSON.Key_messageText, jsonarr.getJSONObject(i).getString("chatText"));
                  hashMap.put(HandleJSON.Key_messageDate, jsonarr.getJSONObject(i).getString("chatDate"));
                  Log.i("dateeeeeee",jsonarr.getJSONObject(i).getString("chatDate"));
  
                  chat.add(hashMap);
  
              }
  
  
              return chat;
        }
        catch(JSONException e)
        {
            return null;
        }
  }
  
  
  public static ArrayList&lt;String&gt; ReturnUsersEmail(String jsonData) throws JSONException
  {
      JSONArray jsonarr=new JSONArray(jsonData);
      ArrayList&lt;String&gt; emails=new ArrayList&lt;String&gt;();
  
      for(int i=0;i&lt;jsonarr.length();i++)
      {
          emails.add(jsonarr.getString(i));
      }
  
      return emails;
  }
  
  
  }
  </code></pre>