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