Note that there are some explanatory texts on larger screens.

plurals
  1. POError while parsing url contains json objects
    text
    copied!<p>I have tried that code for parsing url contain JSON objects but it there is an error at the line :<code>private ProgressDialog progressDialog = new ProgressDialog(ActivitiesActivity.this);</code></p> <p>this ActivitiesActivity to show the list from the json objects .</p> <p>This is the code: </p> <pre><code>class MyAsyncTask extends AsyncTask&lt;String, String, Void&gt; { private ProgressDialog progressDialog = new ProgressDialog(ActivitiesActivity.this); InputStream inputStream = null; String result = ""; protected void onPreExecute() { progressDialog.setMessage("Downloading your data..."); progressDialog.show(); progressDialog.setOnCancelListener(new OnCancelListener() { public void onCancel(DialogInterface arg0) { MyAsyncTask.this.cancel(true); } }); } @Override protected Void doInBackground(String... params) { String url_select = "http://yoururlhere.com"; ArrayList&lt;NameValuePair&gt; param = new ArrayList&lt;NameValuePair&gt;(); try { // Set up HTTP post // HttpClient is more then less deprecated. Need to change to URLConnection HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url_select); httpPost.setEntity(new UrlEncodedFormEntity(param)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); // Read content &amp; Log inputStream = httpEntity.getContent(); } catch (UnsupportedEncodingException e1) { Log.e("UnsupportedEncodingException", e1.toString()); e1.printStackTrace(); } catch (ClientProtocolException e2) { Log.e("ClientProtocolException", e2.toString()); e2.printStackTrace(); } catch (IllegalStateException e3) { Log.e("IllegalStateException", e3.toString()); e3.printStackTrace(); } catch (IOException e4) { Log.e("IOException", e4.toString()); e4.printStackTrace(); } // Convert response to string using String Builder try { BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8); StringBuilder sBuilder = new StringBuilder(); String line = null; while ((line = bReader.readLine()) != null) { sBuilder.append(line + "\n"); } inputStream.close(); result = sBuilder.toString(); } catch (Exception e) { Log.e("StringBuilding &amp; BufferedReader", "Error converting result " + e.toString()); } } // protected Void doInBackground(String... params) protected void onPostExecute(Void v) { //parse JSON data try{ JSONArray jArray = new JSONArray(result); for(int i=0; i &lt; jArray.length(); i++) { JSONObject jObject = jArray.getJSONObject(i); String name = jObject.getString("Title"); String tab1_text = jObject.getString("Date"); //int active = jObject.getInt("active"); } // End Loop this.progressDialog.dismiss(); } catch (JSONException e) { Log.e("JSONException", "Error: " + e.toString()); } // catch (JSONException e) } // protected void onPostExecute(Void v) } //class MyAsyncTask extends AsyncTask&lt;String, String, Void&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload