java - Loading data from web causing error -



java - Loading data from web causing error -

in app, fire onitemclick(..) listner when list view item clicked. in event, load info webpage using next code :-

try { httpclient httpclient = new defaulthttpclient(); httpcontext localcontext = new basichttpcontext(); httpget httpget = new httpget("http://www.spartanjava.com"); httpresponse response = httpclient.execute(httpget, localcontext); string result = ""; bufferedreader reader = new bufferedreader( new inputstreamreader( response.getentity().getcontent() ) ); string line = null; while ((line = reader.readline()) != null){ result += line + "\n"; } } grab (exception e) { tv.settext("error : "+e.getmessage());//tv textview toast.maketext(getapplicationcontext(), "no connection", toast.length_long).show(); e.printstacktrace(); }

i have included next jars in classpath :-

commons-codec-1.6.jar commons-logging-1.1.3.jar httpclient-4.3.3.jar httpclient-cache-4.3.3.jar httpcore-4.3.2.jar httpmime-4.3.3.jar

i have permission <uses-permission android:name="android.permission.internet"/> in anroidmanifext.xml file. output receive in catch-block. textview set value "error : null" , toast fired. thought on how should proceed?

your exception tells doing wrong. not using thread perform networkoperations.

your code connects url should executed within asynctasks doinbackground() method, off ui-thread.

for more info see android.os.networkonmainthreadexception

java android

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -