inputstreamreader - I made a simple android app so far and its not working. InputBufferedReader is the cause I think -
added alot of tv.settext( ) in order know of lines being executed , try block breaks. ending result of 'tv' 4.
public class main extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); textview tv = (textview) findviewbyid(r.id.textview); bufferedreader reader = null; try{ tv.settext("1"); url url = new url("https://www.google.com"); tv.settext("2"); httpurlconnection conn = (httpurlconnection) url.openconnection(); tv.settext("3"); stringbuilder sb = new stringbuilder(); tv.settext("4"); reader = new bufferedreader(new inputstreamreader(conn.getinputstream())); tv.settext("5"); string line; tv.settext("6"); while((line = reader.readline()) != null){ tv.append(line + "\n"); } }catch (exception e){ //tv.settext("exception"); } }
i using android studio , logcat :
04-22 23:38:25.990 28870-28870/com.example.taha.url e/trace﹕ error opening trace file: no such file or directory (2) 04-22 23:38:26.118 28870-28870/com.example.taha.url e/linker﹕ load_library(linker.cpp:759): library "libmaliinstr.so" not found 04-22 23:38:26.125 28870-28870/com.example.taha.url e/﹕ appname=com.example.taha.url, acappname=com.android.cts.openglperf 04-22 23:38:26.125 28870-28870/com.example.taha.url e/﹕ 0 04-22 23:38:26.125 28870-28870/com.example.taha.url e/﹕ appname=com.example.taha.url, acappname=com.android.browser 04-22 23:38:26.125 28870-28870/com.example.taha.url e/﹕ 0
you can't perform network operation on main thread can use asynctask
, put network operation inside doinbackground method of asynctask class .
check out : http://developer.android.com/training/basics/network-ops/connecting.html#asynctask
Comments
Post a Comment