Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are trying to do network tasks on the UI thread. This is not allowed. You must do the network requests in a separate thread i.e extend AsyncTask</p> <p>I will post the code, only because it is a tutorial and I happened to look at this myself some time ago. You can see that AsyncTask is used:</p> <pre><code>public class HTTPGetter extends Activity implements OnClickListener { TextView tvHttp; BufferedReader in = null; EditText ethttp; Button bhttp; String returned, strhttp; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.httpex); tvHttp = (TextView) findViewById(R.id.tvHTTP); bhttp = (Button) findViewById(R.id.bhttp); ethttp = (EditText) findViewById(R.id.ethttp); bhttp.setOnClickListener(this); } private class HTTPGet extends AsyncTask&lt;String, Void, String&gt; { BufferedReader in = null; String returned = null; @Override protected String doInBackground(String... params) { try { HttpClient client = new DefaultHttpClient(); URI website = new URI(strhttp); HttpGet request = new HttpGet(); request.setURI(website); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response .getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String l = ""; String nl = System.getProperty("line.separator"); while ((l = in.readLine()) != null) { sb.append(l + nl); } in.close(); returned = sb.toString(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String result) { super.onPostExecute(result); tvHttp.setText(returned); } } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bhttp: strhttp = ethttp.getText().toString(); HTTPGet test = new HTTPGet(); try { test.execute(strhttp); } catch (Exception e) { e.printStackTrace(); } break; } } } </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.
 

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