0
我从url下载图像并设置为Imageview.but有时候位图返回null? 为什么会这样?.. 我的代码是android上的图像问题
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;
是否会抛出这些异常?如果有,您可以发布堆栈跟踪和/或异常类型和消息。它可能是你的Url格式不正确或某种IO异常被抛出,你无所事事“处理”它。 – Khalos 2010-11-09 11:13:47
你可以检查你的Logcat,确保你是这个Error Skia Decoder,返回False。 – 2010-11-09 11:14:16