Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should do network operations (connection and so on) from a different thread than the main (UI) thread. That's what the error <code>android.os.NetworkOnMainThreadException</code> you are getting means.</p> <p>You should look either into ASyncTask or Thread to do that.</p> <p>Read <a href="http://android-developers.blogspot.com/2009/05/painless-threading.html" rel="nofollow">this article</a> too...</p> <p>Replace the code you currently have with this:</p> <pre><code> AsyncTask&lt;Void,Void,Void&gt; my_task = new AsyncTask&lt;Void,Void,Void&gt;() { @Override protected void onPostExecute() { TextView tv = (TextView) findViewById(R.id.txtTest); tv.setText(result.toString()); } @Override protected Void doInBackground(Void... voids) { InputStream is = null; String result = ""; String url = "http://10.0.2.2/android/try.php"; HttpClient httpclient = new DefaultHttpClient(); try { HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); Log.d("myapp", "response " + response.getEntity()); HttpEntity entity = response.getEntity(); is = entity.getContent(); String st = EntityUtils.toString(response.getEntity()); } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } // convert response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "UTF-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } } }.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.
 

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