java - HttpConnection failing on .connect() for image URL -


i'm trying retrieve tweet information search query android application. i'm able put username , subject in listview, have trouble grabbing photo. here getview method adapter

 @override  public view getview(int position, view convertview, viewgroup parent) {         view v = convertview;         if (v == null) {             layoutinflater vi = (layoutinflater)getsystemservice(context.layout_inflater_service);             v = vi.inflate(r.layout.listitem, null);         }          userrecord user = users.get(position);         if (user != null) {             textview username = (textview) v.findviewbyid(r.id.username);             textview subject = (textview) v.findviewbyid(r.id.subject);             // bitmap bitmap = downloadimage(user.imageurl);             imageview img = (imageview) v.findviewbyid(r.id.avatar);             if (username != null) {                 username.settext(user.username);             }              if(subject != null) {                 subject.settext(user.subject);             }              if (img != null){                 try {                     url myurl = new url(user.imageurl);                     httpurlconnection conn = (httpurlconnection) myurl.openconnection();                     conn.setdoinput(true);                     conn.connect();                     inputstream = conn.getinputstream();                     img.setimagebitmap(bitmapfactory.decodestream(is));                 } catch (exception e) {                     e.printstacktrace();                 }             }         }         return v;     } 

i traced through code , fails on conn.connect() , jumps catch statement. know why happening? have internet connection enabled in mainfest. thanks!

yes, jump catch statement, , give follwing exceptions, 1.networkonmainthreadexception

2.nullpointerexception

first 1 because trying perform network operation on ui thread.

second 1 because input stream null, when trying access it, nullpointerexception.

what need do?

use separate thread or asynctask download images

is best way?

you need cache images when showing images url in listview, try use universalimagedownloader or lazyloadlist populate images


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -