我正在从url下载图像并设置为图像视图。但是有时位图返回空值?
为什么会这样?。。
我的密码是
Bitmap bm = null;
URL myFileUrl =null;
try
{
myFileUrl= new URL(url);
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
InputStream is = conn.getInputStream();
bm = BitmapFactory.decodeStream(is);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return bm;