Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy this doesn't work for ICS
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/8995364/strange-networkonmainthreadexception-in-android-app">Strange NetworkOnMainThreadException in Android app?</a><br> <a href="https://stackoverflow.com/questions/10892858/trying-to-upload-to-dropbox-networkonmainthreadexception">Trying To Upload To Dropbox: NetworkOnMainThreadException?</a> </p> </blockquote> <p>I have used the below code for reading HTML contents from a url. This works perfectly for 2.3.3 but when I try to run the same code it doesn't work for ICS. </p> <p>I am trying to append these html contents on to a <code>edittext</code>. But it always remains empty when I run the code on ICS. What may be the problem?</p> <pre><code>public class Quiz1Activity extends Activity { private static BufferedReader reader = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); EditText ed = (EditText) findViewById(R.id.editText1); try { ed.append(getStringFromUrl("http://www.google.com")); //getInputStreamFromUrl("").close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static InputStream getInputStreamFromUrl(String url){ InputStream contentStream = null; try{ HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpGet(url)); contentStream = response.getEntity().getContent(); } catch(Exception e){ e.printStackTrace(); } System.out.println("Content stream is " + contentStream); return contentStream; } public static String getStringFromUrl(String url) throws IOException{ reader = new BufferedReader(new InputStreamReader(getInputStreamFromUrl(url))); StringBuilder sb = new StringBuilder(); try{ String line = null; while((line = reader.readLine()) != null) { sb.append(line); } }catch (IOException e){ e.printStackTrace(); } getInputStreamFromUrl(url).close(); return sb.toString(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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