title: Json object integrate with android
body: <p>I have used this code  <a href="http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/" rel="nofollow">http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/</a>  for GCM . But having trouble whenever i click to view or create a new produce button.I have checked the solution that is described below the tutorial but that doesn't solve my problem. here is my </p>
  
  <pre><code>02-14 20:06:09.775: W/KeyCharacterMap(738): No keyboard for id 0
  02-14 20:06:09.775: W/KeyCharacterMap(738): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
  02-14 20:06:13.105: E/JSON Parser(738): Error parsing data org.json.JSONException: Value &lt;!DOCTYPE of type java.lang.String cannot be converted to JSONObject
  02-14 20:06:13.105: W/dalvikvm(738): threadid=9: thread exiting with uncaught exception (group=0x40015560)
  02-14 20:06:13.115: E/AndroidRuntime(738): FATAL EXCEPTION: AsyncTask #1
  02-14 20:06:13.115: E/AndroidRuntime(738): java.lang.RuntimeException: An error occured while executing doInBackground()
  02-14 20:06:13.115: E/AndroidRuntime(738):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at java.lang.Thread.run(Thread.java:1019)
  02-14 20:06:13.115: E/AndroidRuntime(738): Caused by: java.lang.NullPointerException
  02-14 20:06:13.115: E/AndroidRuntime(738):  at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:130)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
  02-14 20:06:13.115: E/AndroidRuntime(738):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  02-14 20:06:13.115: E/AndroidRuntime(738):  ... 4 more
  02-14 20:06:14.213: E/WindowManager(738): Activity com.example.androidhive.AllProductsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405375e0 that was originally added here
  02-14 20:06:14.213: E/WindowManager(738): android.view.WindowLeaked: Activity com.example.androidhive.AllProductsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405375e0 that was originally added here
  02-14 20:06:14.213: E/WindowManager(738):   at android.view.ViewRoot.&lt;init&gt;(ViewRoot.java:258)
  02-14 20:06:14.213: E/WindowManager(738):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
  02-14 20:06:14.213: E/WindowManager(738):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
  02-14 20:06:14.213: E/WindowManager(738):   at android.view.Window$LocalWindowManager.addView(Window.java:424)
  02-14 20:06:14.213: E/WindowManager(738):   at android.app.Dialog.show(Dialog.java:241)
  02-14 20:06:14.213: E/WindowManager(738):   at com.example.androidhive.AllProductsActivity$LoadAllProducts.onPreExecute(AllProductsActivity.java:117)
  02-14 20:06:14.213: E/WindowManager(738):   at android.os.AsyncTask.execute(AsyncTask.java:391)
  02-14 20:06:14.213: E/WindowManager(738):   at com.example.androidhive.AllProductsActivity.onCreate(AllProductsActivity.java:57)
  02-14 20:06:14.213: E/WindowManager(738):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  02-14 20:06:14.213: E/WindowManager(738):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  02-14 20:06:14.213: E/WindowManager(738):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  02-14 20:06:14.213: E/WindowManager(738):   at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  02-14 20:06:14.213: E/WindowManager(738):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  02-14 20:06:14.213: E/WindowManager(738):   at android.os.Handler.dispatchMessage(Handler.java:99)
  02-14 20:06:14.213: E/WindowManager(738):   at android.os.Looper.loop(Looper.java:123)
  02-14 20:06:14.213: E/WindowManager(738):   at android.app.ActivityThread.main(ActivityThread.java:3683)
  02-14 20:06:14.213: E/WindowManager(738):   at java.lang.reflect.Method.invokeNative(Native Method)
  02-14 20:06:14.213: E/WindowManager(738):   at java.lang.reflect.Method.invoke(Method.java:507)
  02-14 20:06:14.213: E/WindowManager(738):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  02-14 20:06:14.213: E/WindowManager(738):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  02-14 20:06:14.213: E/WindowManager(738):   at dalvik.system.NativeStart.main(Native Method)
  02-14 20:06:25.245: I/Process(738): Sending signal. PID: 738 SIG: 9
  </code></pre>
  
  <p>Here is my asynctask code --- </p>
  
  <pre><code>/**
       * Background Async Task to Load all product by making HTTP Request
       * */
      class LoadAllProducts extends AsyncTask&lt;String, String, String&gt; {
  
          /**
           * Before starting background thread Show Progress Dialog
           * */
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(AllProductsActivity.this);
              pDialog.setMessage("Loading products. 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_products, "GET", params);
  
              // Check your log cat for JSON reponse
              Log.d("All Products: ", json.toString());
  
              try {
                  // Checking for SUCCESS TAG
                  int success = json.getInt(TAG_SUCCESS);
  
                  if (success == 1) {
                      // products found
                      // Getting Array of Products
                      products = json.getJSONArray(TAG_PRODUCTS);
  
                      // looping through All Products
                      for (int i = 0; i &lt; products.length(); i++) {
                          JSONObject c = products.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
                          productsList.add(map);
                      }
                  } else {
                      // no products found
                      // Launch Add New product Activity
                      Intent i = new Intent(getApplicationContext(),
                              NewProductActivity.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(
                              AllProductsActivity.this, productsList,
                              R.layout.list_item, new String[] { TAG_PID,
                                      TAG_NAME},
                              new int[] { R.id.pid, R.id.name });
                      // updating listview
                      setListAdapter(adapter);
                  }
              });
  
          }
  
      }
  </code></pre>
  
  <p>after doing the thing that ben has said ...the length of error has reduced ..... now having only this error -- </p>
  
  <pre><code>02-14 20:39:06.094: E/JSON Parser(1182): Error parsing data org.json.JSONException: Value &lt;!DOCTYPE of type java.lang.String cannot be converted to JSONObject
  02-14 20:39:06.094: W/dalvikvm(1182): threadid=9: thread exiting with uncaught exception (group=0x40015560)
  02-14 20:39:06.104: E/AndroidRuntime(1182): FATAL EXCEPTION: AsyncTask #1
  02-14 20:39:06.104: E/AndroidRuntime(1182): java.lang.RuntimeException: An error occured while executing doInBackground()
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at java.lang.Thread.run(Thread.java:1019)
  02-14 20:39:06.104: E/AndroidRuntime(1182): Caused by: java.lang.NullPointerException
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:137)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  02-14 20:39:06.104: E/AndroidRuntime(1182):     ... 4 more
  </code></pre>