title: A null JSONObject reference and leaked activity
body: <p>I am developing a server connected Android app using PHP at server-side to store data through MySQL. So, if I try to summarize, below is the errors in my LogCat:</p>
  
  <pre><code>03-18 01:54:50.952    1930-2127/com.example.umitkaya.usermaintenanceactivity E/JSON Parser﹕ Error parsing data org.json.JSONException: End of input at character 1 of
  --------- beginning of crash
  03-18 01:54:50.977    1930-2127/com.example.umitkaya.usermaintenanceactivity E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
  Process: com.example.umitkaya.usermaintenanceactivity, PID: 1930
  java.lang.RuntimeException: An error occured while executing doInBackground()
          at android.os.AsyncTask$3.done(AsyncTask.java:300)
          at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
          at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
          at java.util.concurrent.FutureTask.run(FutureTask.java:242)
          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
          at java.lang.Thread.run(Thread.java:818)
   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
          at com.example.umitkaya.usermaintenanceactivity.AllUserActivity$LoadAllUser.doInBackground(AllUserActivity.java:129)
          at com.example.umitkaya.usermaintenanceactivity.AllUserActivity$LoadAllUser.doInBackground(AllUserActivity.java:104)
          at android.os.AsyncTask$2.call(AsyncTask.java:288)
          at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  03-18 01:54:54.127    1930-1930/com.example.umitkaya.usermaintenanceactivity E/WindowManager﹕ android.view.WindowLeaked: Activity com.example.umitkaya.usermaintenanceactivity.AllUserActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{97d499 V.E..... R......D 0,0-1026,348} that was originally added here
          at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:363)
          at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261)
          at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
          at android.app.Dialog.show(Dialog.java:298)
          at com.example.umitkaya.usermaintenanceactivity.AllUserActivity$LoadAllUser.onPreExecute(AllUserActivity.java:116)
          at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
          at android.os.AsyncTask.execute(AsyncTask.java:535)
          at com.example.umitkaya.usermaintenanceactivity.AllUserActivity.onCreate(AllUserActivity.java:59)
          at android.app.Activity.performCreate(Activity.java:5933)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
          at android.app.ActivityThread.access$800(ActivityThread.java:144)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5221)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>
  
  <p>And this is my source code:</p>
  
  <pre><code>public class AllUserActivity extends ListActivity{
  
  // Progress Dialog
  private ProgressDialog pDialog;
  
  // Creating JSON Parser object
  JSONParser jParser = new JSONParser();
  
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; userList;
  
  // url to get all products list
  private static String url_all_user = "http://10.0.2.2:8080/android_connect/get_all_users.php";
  
  // JSON Node names
  private static final String TAG_SUCCESS = "success";
  private static final String TAG_USER = "user";
  private static final String TAG_PID = "pid";
  private static final String TAG_NAME = "name";
  
  // products JSONArray
  JSONArray user = null;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.all_user);
  
      // Hashmap for ListView
      userList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      // Loading products in Background Thread
      new LoadAllUser().execute();
  
      // Get listview
      ListView lv = getListView();
  
      // on seleting single product
      // launching Edit Product Screen
      lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
              // getting values from selected ListItem
              String pid = ((TextView) view.findViewById(R.id.pid)).getText()
                      .toString();
  
              // Starting new intent
              Intent in = new Intent(getApplicationContext(),
                      EditUserActivity.class);
              // sending pid to next activity
              in.putExtra(TAG_PID, pid);
  
              // starting new activity and expecting some response back
              startActivityForResult(in, 100);
          }
      });
  }
  // Response from Edit Product Activity
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      // if result code 100
      if (resultCode == 100) {
          // if result code 100 is received
          // means user edited/deleted product
          // reload this screen again
          Intent intent = getIntent();
          finish();
          startActivity(intent);
      }
  }
  
  /**
   * Background Async Task to Load all product by making HTTP Request
   * */
  class LoadAllUser extends AsyncTask&lt;String, String, String&gt; {
  
      /**
       * Before starting background thread Show Progress Dialog
       * */
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(AllUserActivity.this);
          pDialog.setMessage("Loading users. Please wait...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(false);
          pDialog.show();
      }
  
      /**
       * getting All products from url
       * */
      protected String doInBackground(String... args) {
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          // getting JSON string from URL
          JSONObject json = jParser.makeHttpRequest(url_all_user, "GET", params);
  
          // Check your log cat for JSON reponse
          Log.d("All User: ", json.toString());
  
          try {
              // Checking for SUCCESS TAG
              int success = json.getInt(TAG_SUCCESS);
  
              if (success == 1) {
                  // products found
                  // Getting Array of Products
                  user = json.getJSONArray(TAG_USER);
  
                  // looping through All Products
                  for (int i = 0; i &lt; user.length(); i++) {
                      JSONObject c = user.getJSONObject(i);
  
                      // Storing each json item in variable
                      String id = c.getString(TAG_PID);
                      String name = c.getString(TAG_NAME);
  
                      // creating new HashMap
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                      // adding each child node to HashMap key =&gt; value
                      map.put(TAG_PID, id);
                      map.put(TAG_NAME, name);
  
                      // adding HashList to ArrayList
                      userList.add(map);
                  }
              } else {
                  // no products found
                  // Launch Add New product Activity
                  Intent i = new Intent(getApplicationContext(),
                          NewUserActivity.class);
                  // Closing all previous activities
                  i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  startActivity(i);
              }
          } catch (JSONException e) {
  
              e.printStackTrace();
          }
  
          return null;
      }
  
      /**
       * After completing background task Dismiss the progress dialog
       * **/
      protected void onPostExecute(String file_url) {
          // dismiss the dialog after getting all products
          pDialog.dismiss();
          // updating UI from Background Thread
          runOnUiThread(new Runnable() {
              public void run() {
                  /**
                   * Updating parsed JSON data into ListView
                   * */
                  ListAdapter adapter = new SimpleAdapter(
                          AllUserActivity.this, userList,
                          R.layout.list_iteam, new String[] { TAG_PID,
                          TAG_NAME},
                          new int[] { R.id.pid, R.id.name });
                  // updating listview
                  setListAdapter(adapter);
              }
          });
      }
   }
  }
  </code></pre>
  
  <p>Connection with the server side has no problem. The issue is with my Android code. I appreciate helps.</p>