setImageURI / setimagebitmap to fetch image from net and display in image view

萝らか妹 提交于 2019-12-06 07:37:46

I think the error is in

URL aURL = new URL("stringURL");

should be without quotes

URL aURL = new URL(stringURL);

if stringURL is valid url it will work...

hope it helps../

I think better you can use below code, which works very well for me.

String stringURL = "Your url here";

InputStream is = null;
BufferedInputStream bis = null;
Bitmap bmp = null;

try {
    URL url = new URL(stringURL);   
    URLConnection conn = url.openConnection();
    conn.connect();
    is = conn.getInputStream();
    bis = new BufferedInputStream(is);
    bmp = BitmapFactory.decodeStream(bis);

} catch (MalformedURLException e) {

} catch (IOException e) {

}catch (Exception e) {

} finally {
    try {
        if( is != null )
            is.close();
        if( bis != null )
            bis.close();
    } catch (IOException e) {

    }
}
iv.setImageBitmap(bmp);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!