Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>Caused by: android.os.NetworkOnMainThreadException </code></pre> <p>This means that you're doing your HTTP request on the main thread. Since <strong>Android Honeycomb</strong> version, this way isn't good anymore. You've to use a <strong>second thread</strong> (in fact a <code>background thread</code>) to implement your HTTP request. </p> <p>Why ? </p> <p>Because, if you're running your network method in the main thread, the UI is blocked and the user cannot do anything until your method comes to the end. </p> <p>How to : </p> <p>Use an AsyncTask class that <code>extends AsyncTask&lt;String, String, String&gt;</code> and do your stuff in the <code>DoInBackground</code> method. On the <code>OnpostExcute</code>, you can handle the response.</p> <p>See <a href="http://developer.android.com/reference/android/os/AsyncTask.html" rel="nofollow">Android Developers Post</a></p> <p>This is the response of your issue : </p> <pre><code>class Async extends AsyncTask&lt;String, String, String&gt; { @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(MyActivity.this); progressDialog.setTitle("Merci de patienter"); progressDialog.setMessage("Chargement en cours"); progressDialog.setCancelable(false); progressDialog.setIndeterminate(true); progressDialog.show(); } @Override protected String doInBackground(String... aurl) { try { HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet("http://localhost"); HttpResponse response = client.execute(get); StatusLine status = response.getStatusLine(); String data = status.toString(); return data; } catch (Exception e) {} return null; } @Override protected void onPostExecute(String result) { if (progressDialog!=null) { progressDialog.dismiss(); } tvStatus.setText(result); } } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.json); tvStatus = (TextView) findViewById(R.id.tvStatus); new Async().execute(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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