inputstream - Using imageview by url in android -


i try photo url not photo.

current code:

public class indexactivity extends activity { @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);     imageview = (imageview) findviewbyid(r.id.imageview1);     bitmap bitmap = downloadimage("http://www.gophoto.it/view.php?i=http://1.bp.blogspot.com/-2ltvccufbkc/t3l3kgctj2i/aaaaaaaabbq/ki60e1lu9se/s1600/sachin%2btendulkar.png");     i.setimagebitmap(bitmap); }  private inputstream openhttpconnection(string urlstring) throws ioexception {     inputstream in = null;     int response = -1;      url url = new url(urlstring);     urlconnection conn = url.openconnection();      if (!(conn instanceof httpurlconnection))         throw new ioexception("not http connection");      try {         httpurlconnection httpconn = (httpurlconnection) conn;         httpconn.setallowuserinteraction(false);         httpconn.setinstancefollowredirects(true);         httpconn.setrequestmethod("get");         httpconn.connect();         response = httpconn.getresponsecode();         if (response == httpurlconnection.http_ok) {             in = httpconn.getinputstream();         }     } catch (exception ex) {         throw new ioexception("error connecting");     }     return in; }  private bitmap downloadimage(string url) {     bitmap bitmap = null;     inputstream in = null;     try {         in = openhttpconnection(url);         bitmap = bitmapfactory.decodestream(in);         in.close();     } catch (ioexception e1) {         // todo auto-generated catch block         e1.printstacktrace();     }     return bitmap;     } } 

and the loccat :

08-01 08:53:17.818: d/activitythread(12315): handleresumeactivity pri:0 08-01 08:53:17.818: d/activitythread(12315): handleresumeactivity set pri:0 08-01 08:53:20.268: w/system.err(12315): java.io.ioexception: error connecting 08-01 08:53:20.268: w/system.err(12315):    @ tr.com.turkcell.shmobile.indexactivity.openhttpconnection(indexactivity.java:70) 08-01 08:53:20.268: w/system.err(12315):    @ tr.com.turkcell.shmobile.indexactivity.downloadimage(indexactivity.java:79) 08-01 08:53:20.268: w/system.err(12315):    @ tr.com.turkcell.shmobile.indexactivity.oncreate(indexactivity.java:32) 08-01 08:53:20.268: w/system.err(12315):    @ android.app.activity.performcreate(activity.java:5008) 08-01 08:53:20.268: w/system.err(12315):    @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1093) 08-01 08:53:20.268: w/system.err(12315):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 08-01 08:53:20.268: w/system.err(12315):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 08-01 08:53:20.268: w/system.err(12315):    @ android.app.activitythread.access$600(activitythread.java:130) 08-01 08:53:20.268: w/system.err(12315):    @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 08-01 08:53:20.278: w/system.err(12315):    @ android.os.handler.dispatchmessage(handler.java:99) 08-01 08:53:20.278: w/system.err(12315):    @ android.os.looper.loop(looper.java:137) 08-01 08:53:20.278: w/system.err(12315):    @ android.app.activitythread.main(activitythread.java:4754) 08-01 08:53:20.278: w/system.err(12315):    @ java.lang.reflect.method.invokenative(native method) 08-01 08:53:20.278: w/system.err(12315):    @ java.lang.reflect.method.invoke(method.java:511) 08-01 08:53:20.278: w/system.err(12315):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833) 08-01 08:53:20.278: w/system.err(12315):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600) 08-01 08:53:20.278: w/system.err(12315):    @ dalvik.system.nativestart.main(native method) 08-01 08:53:20.278: d/activitythread(12315): handleresumeactivity pri:0 08-01 08:53:20.278: d/activitythread(12315): handleresumeactivity set pri:0 

what doing wrong calling long running task on main ui thread.

use asyncktask's onpostexecute method downloaded image bitmap. bind imageview object returned bitmap.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -