我在这里遇到了一个问题。
我在列表中有一些图片网址
agenda.get(i).getPicture() // always return a good image url
在线程中我这样做:
for (int i = 0; i < agenda.size(); i ++)
{
Log.e("TEST", " = " +agenda.get(i).getPicture());
Bitmap newBitmap = getBitmapFromURL(agenda.get(i).getPicture()); // getPicture return the url
imagelist.add(i,newBitmap);
}
getBitmapFromURL返回null原因:
BitmapFactory.decodeStream(input)
in:
private Bitmap getBitmapFromURL(final String src) {
Runnable r=new Runnable()
{
public void run() {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
myBitmap = BitmapFactory.decodeStream(input);
connection.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
};
return myBitmap;
}
现在,如果有人有想法PLZ! 感谢
编辑!
有可能
InputStream input = connection.getInputStream();
也失败了......我不知道为什么