title: POST request in android with OnClick listview
body: <h2>I am trying to dynamically pass the data to next activity by making a post request to server</h2>
  
  <hr>
  
  <p><strong>My Analysis::</strong></p>
  
  <ul>
  <li>I am not able to determine whether the error is on server on express or the android client
  code</li>
  </ul>
  
  <p><strong>Or</strong></p>
  
  <ul>
  <li>Whether i am making a proper post request to server in Async task</li>
  </ul>
  
  <hr>
  
  <p><strong>[Note]</strong> </p>
  
  <p>Data from <strong><code>Url</code></strong> variable is displaying in the list view
  But
  Onclick of listrow .... where a post request need to be made to server and a JSON response had to be retrieved is the place where error is appearing </p>
  
  <hr>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  
      // url to make request
      private static String url = "http://54.218.73.244:7003/";
  
      private static String url1 = "http://54.218.73.244:7003/RestaurantDesc/";
  
  
  
      String item;
      private HashMap&lt;Integer, String&gt; TimeMap = new HashMap&lt;Integer, String&gt;();
  
      List&lt;Item&gt; yourData = new ArrayList&lt;Item&gt;();
  
      ProgressDialog progressDialog;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          //Instantiating ProgressDialog with onCreate method
          progressDialog=new ProgressDialog(MainActivity.this);
          new ParsingAsync().execute();
  
      }
  
      private class ParsingAsync extends AsyncTask&lt;Void, Void, Void&gt;
      {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              progressDialog=ProgressDialog.show(MainActivity.this, "", "Please Wait", true, false);
  
  
          }
  
          @Override
          protected Void doInBackground(Void... params) {
              // TODO Auto-generated method stub
  
  
              String _response = null;
              try
              {
              HttpClient httpclient = new DefaultHttpClient();
              httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
              HttpGet request = new HttpGet(url);
              HttpResponse response = httpclient.execute(request);
              HttpEntity resEntity = response.getEntity();
               _response =EntityUtils.toString(resEntity);
              JSONObject jsonObject = new JSONObject(_response);
              JSONArray first_array = jsonObject.getJSONArray("restaurants");
              JSONArray second_array = jsonObject.getJSONArray("RestaurantTimings");
               for(int i=0;i&lt;first_array.length();i++)
               {
                      JSONObject c = second_array.getJSONObject(i);
                      Item item = new Item();
  
                      // Storing each json item in variable
                      int id = c.getInt("_id");
                      String TIME = c.getString("RestaurantTime");
                      item.setTime(TIME);
  
                      c = first_array.getJSONObject(i);
  
                      String NAME=c.getString("restaurantNAME");
                      item.setName(NAME);
  
                      String URL=c.getString("url");
                      item.setUrl(URL);
  
  
                      yourData.add(item);
                  }
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (ClientProtocolException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
              return null;
  
          }
  
          @Override
          protected void onPostExecute(Void result) {
              // TODO Auto-generated method stub
              super.onPostExecute(result);
              progressDialog.dismiss();
  
              TextView timedisplay=(TextView) findViewById(R.id.RestaurantTimeID);
  
  
              ListView yourListView = (ListView) findViewById(R.id.listViewID);
              ListAdapter customAdapter = new ListAdapter(MainActivity.this, R.layout.itemlistrow, yourData);
              yourListView.setAdapter(customAdapter);
              yourListView.setOnItemClickListener(new OnItemClickListener() {
  
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                          int position, long id) {
                      item = yourData.get(position).getName();
  
  
                      HttpClient httpclient = new DefaultHttpClient();
                      HttpPost httppost = new HttpPost(url1);
  
                      try {
                          // Add your data
                          List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
                          nameValuePairs.add(new BasicNameValuePair("Key", item));
                          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
                          // Execute HTTP Post Request
                          HttpResponse response = httpclient.execute(httppost);
  
                      } catch (ClientProtocolException e) {
                          // TODO Auto-generated catch block
                      } catch (IOException e) {
                          // TODO Auto-generated catch block
                      }
  
  
                      Intent i = new Intent(MainActivity.this, RestaurantDesc.class);
                      i.putExtra("key", url1);
                      i.putExtra("CC_RES",item.toString());
                      startActivity(i);
  
                  }
              });
          }
  
      }
  
  }
  </code></pre>
  
  <p><strong>Part of Express code on server::</strong></p>
  
  <pre><code>app.get('/RestaurantDesc/:Key',function(request,response,next){
  
      var keyName=request.params.Key;
      var name_of_restaurants, RestaurantTimings;
  
      async.series( [
          // Get the first table contents
          function ( callback ) {
              connection.query('SELECT * FROM ', keyName, function(err, rows, fields)
                  {
                          console.log('Connection result error '+err);
                          name_of_restaurants = rows;
                          callback();
                  });
          },
          // Get the second table contents
          function ( callback ) {
          connection.query('SELECT * FROM ', RestaurantTimings, function(err, rows, fields)
  
              {
                      console.log('Connection result error '+err);
                      RestaurantTimings = rows;
                      callback();
              });
          }
  
     // Send the response
  ], function ( error, results ) {
      response.json({
          'restaurants' : name_of_restaurants,
          'RestaurantTimings' : RestaurantTimings
      });
  } );
  } );
  </code></pre>
  
  <p><strong>[LOG]</strong></p>
  
  <pre><code>08-29 08:20:01.963: W/dalvikvm(333): threadid=6: spin on suspend #1 threadid=9 (pcf=0)
  08-29 08:20:01.963: D/dalvikvm(333): Temporarily moving tid 342 to fg (was 0)
  08-29 08:20:01.963: D/dalvikvm(333): Temporarily raised priority on tid 342 (10 -&gt; 0)
  08-29 08:20:02.041: W/dalvikvm(333): threadid=6: spin on suspend resolved in 1081 msec
  08-29 08:20:02.041: D/dalvikvm(333): Restored policy of 342 to 0
  08-29 08:20:02.041: D/dalvikvm(333): Restored priority on 342 to 10
  08-29 08:20:12.541: D/dalvikvm(333): GC_EXTERNAL_ALLOC freed 177K, 48% free 3078K/5895K, external 2111K/2137K, paused 86ms
  08-29 08:20:18.042: W/System.err(333): org.json.JSONException: Value Cannot of type java.lang.String cannot be converted to JSONObject
  08-29 08:20:18.042: W/System.err(333):  at org.json.JSON.typeMismatch(JSON.java:107)
  08-29 08:20:18.062: W/System.err(333):  at org.json.JSONObject.&lt;init&gt;(JSONObject.java:158)
  08-29 08:20:18.062: W/System.err(333):  at org.json.JSONObject.&lt;init&gt;(JSONObject.java:171)
  08-29 08:20:18.062: W/System.err(333):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.doInBackground(RestaurantDesc.java:114)
  08-29 08:20:18.062: W/System.err(333):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.doInBackground(RestaurantDesc.java:1)
  08-29 08:20:18.072: W/System.err(333):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
  08-29 08:20:18.072: W/System.err(333):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  08-29 08:20:18.072: W/System.err(333):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  08-29 08:20:18.072: W/System.err(333):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  08-29 08:20:18.072: W/System.err(333):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  08-29 08:20:18.082: W/System.err(333):  at java.lang.Thread.run(Thread.java:1019)
  08-29 08:20:18.082: D/AndroidRuntime(333): Shutting down VM
  08-29 08:20:18.082: W/dalvikvm(333): threadid=1: thread exiting with uncaught exception (group=0x40015560)
  08-29 08:20:18.112: E/AndroidRuntime(333): FATAL EXCEPTION: main
  08-29 08:20:18.112: E/AndroidRuntime(333): java.lang.NullPointerException
  08-29 08:20:18.112: E/AndroidRuntime(333):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.onPostExecute(RestaurantDesc.java:138)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.onPostExecute(RestaurantDesc.java:1)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at android.os.AsyncTask.finish(AsyncTask.java:417)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at android.os.AsyncTask.access$300(AsyncTask.java:127)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at android.os.Handler.dispatchMessage(Handler.java:99)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at android.os.Looper.loop(Looper.java:123)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at android.app.ActivityThread.main(ActivityThread.java:3683)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at java.lang.reflect.Method.invokeNative(Native Method)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at java.lang.reflect.Method.invoke(Method.java:507)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  08-29 08:20:18.112: E/AndroidRuntime(333):  at dalvik.system.NativeStart.main(Native Method)
  08-29 08:25:02.411: I/Process(333): Sending signal. PID: 333 SIG: 9
  08-29 08:25:49.932: D/dalvikvm(364): GC_EXTERNAL_ALLOC freed 178K, 48% free 3078K/5895K, external 2111K/2137K, paused 88ms
  08-29 08:25:51.571: W/System.err(364): org.json.JSONException: Value Cannot of type java.lang.String cannot be converted to JSONObject
  08-29 08:25:51.701: W/System.err(364):  at org.json.JSON.typeMismatch(JSON.java:107)
  08-29 08:25:51.862: W/System.err(364):  at org.json.JSONObject.&lt;init&gt;(JSONObject.java:158)
  08-29 08:25:51.941: W/System.err(364):  at org.json.JSONObject.&lt;init&gt;(JSONObject.java:171)
  08-29 08:25:52.043: W/System.err(364):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.doInBackground(RestaurantDesc.java:114)
  08-29 08:25:52.081: W/System.err(364):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.doInBackground(RestaurantDesc.java:1)
  08-29 08:25:52.081: W/System.err(364):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
  08-29 08:25:52.171: W/System.err(364):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  08-29 08:25:52.231: W/System.err(364):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  08-29 08:25:52.251: W/System.err(364):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  08-29 08:25:52.261: W/System.err(364):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  08-29 08:25:52.301: W/System.err(364):  at java.lang.Thread.run(Thread.java:1019)
  08-29 08:25:52.331: D/AndroidRuntime(364): Shutting down VM
  08-29 08:25:52.331: W/dalvikvm(364): threadid=1: thread exiting with uncaught exception (group=0x40015560)
  08-29 08:25:52.361: E/AndroidRuntime(364): FATAL EXCEPTION: main
  08-29 08:25:52.361: E/AndroidRuntime(364): java.lang.NullPointerException
  08-29 08:25:52.361: E/AndroidRuntime(364):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.onPostExecute(RestaurantDesc.java:138)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.onPostExecute(RestaurantDesc.java:1)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at android.os.AsyncTask.finish(AsyncTask.java:417)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at android.os.AsyncTask.access$300(AsyncTask.java:127)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at android.os.Handler.dispatchMessage(Handler.java:99)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at android.os.Looper.loop(Looper.java:123)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at android.app.ActivityThread.main(ActivityThread.java:3683)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at java.lang.reflect.Method.invokeNative(Native Method)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at java.lang.reflect.Method.invoke(Method.java:507)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  08-29 08:25:52.361: E/AndroidRuntime(364):  at dalvik.system.NativeStart.main(Native Method)
  08-29 08:26:12.072: I/Process(364): Sending signal. PID: 364 SIG: 9
  08-29 08:26:38.353: D/dalvikvm(396): GC_EXTERNAL_ALLOC freed 179K, 48% free 3078K/5895K, external 2111K/2137K, paused 88ms
  08-29 08:26:40.043: W/System.err(396): org.json.JSONException: Value Cannot of type java.lang.String cannot be converted to JSONObject
  08-29 08:26:40.353: W/System.err(396):  at org.json.JSON.typeMismatch(JSON.java:107)
  08-29 08:26:40.562: W/System.err(396):  at org.json.JSONObject.&lt;init&gt;(JSONObject.java:158)
  08-29 08:26:40.562: W/System.err(396):  at org.json.JSONObject.&lt;init&gt;(JSONObject.java:171)
  08-29 08:26:40.562: W/System.err(396):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.doInBackground(RestaurantDesc.java:114)
  08-29 08:26:40.562: W/System.err(396):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.doInBackground(RestaurantDesc.java:1)
  08-29 08:26:40.562: W/System.err(396):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
  08-29 08:26:40.562: W/System.err(396):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  08-29 08:26:40.562: W/System.err(396):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  08-29 08:26:40.562: W/System.err(396):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  08-29 08:26:40.571: W/System.err(396):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  08-29 08:26:40.571: W/System.err(396):  at java.lang.Thread.run(Thread.java:1019)
  08-29 08:26:40.633: D/AndroidRuntime(396): Shutting down VM
  08-29 08:26:40.633: W/dalvikvm(396): threadid=1: thread exiting with uncaught exception (group=0x40015560)
  08-29 08:26:40.682: E/AndroidRuntime(396): FATAL EXCEPTION: main
  08-29 08:26:40.682: E/AndroidRuntime(396): java.lang.NullPointerException
  08-29 08:26:40.682: E/AndroidRuntime(396):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.onPostExecute(RestaurantDesc.java:138)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at com.project.findmybuffet.RestaurantDesc$ParsingAsync.onPostExecute(RestaurantDesc.java:1)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at android.os.AsyncTask.finish(AsyncTask.java:417)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at android.os.AsyncTask.access$300(AsyncTask.java:127)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at android.os.Handler.dispatchMessage(Handler.java:99)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at android.os.Looper.loop(Looper.java:123)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at android.app.ActivityThread.main(ActivityThread.java:3683)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at java.lang.reflect.Method.invokeNative(Native Method)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at java.lang.reflect.Method.invoke(Method.java:507)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  08-29 08:26:40.682: E/AndroidRuntime(396):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p><strong>Hope i am clear</strong> </p>
  
  <p><em>Thanks</em></p>