java - http get in android async task -
when implement says "networkonmainthreadexception".
could post illustration works?
i have tried many different examples , libraries, didnt work. code:
private class httpgetter extends asynctask<url, void, void> { @override protected void doinbackground(url... urls) { // todo auto-generated method stub stringbuilder builder = new stringbuilder(); httpclient client = new defaulthttpclient(); httpget httpget = new httpget(string.valueof(urls[0])); seek { httpresponse response = client.execute(httpget); statusline statusline = response.getstatusline(); int statuscode = statusline.getstatuscode(); if (statuscode == 200) { httpentity entity = response.getentity(); inputstream content = entity.getcontent(); bufferedreader reader = new bufferedreader( new inputstreamreader(content)); string line; while ((line = reader.readline()) != null) { builder.append(line); } log.v("getter", "your data: " + builder.tostring()); //response info } else { log.e("getter", "failed download file"); } } grab (clientprotocolexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } homecoming null; } }
you should execute task new httpgetter().execute(url)
note asynctask
can executed once.
java android android-asynctask android-networking
No comments:
Post a Comment