我正在开发一个 Android 应用程序,它的视图包含多个图库。画廊(位图)的内容是来自互联网的红色。
对于第一个画廊,一切正常,但是当尝试下载第二个画廊的第一个图像时,BitmapFactory.decodeStream(InputStream)
返回 null,而流不为 null。
public void loadBitmap() throws IOException {
for (int i = 0; i < images.size(); ++i) {
URL ulrn = new URL(images.get(i).getThumbUrl());
HttpURLConnection con = (HttpURLConnection) ulrn.openConnection();
InputStream is = con.getInputStream();
images.get(i).setImage(BitmapFactory.decodeStream(is));
Log.i("MY_TAG", "Height: " + images.get(i).getImage().getHeight());
}
}
返回图像的getThumbUrl()
URL(例如http://mydomain.com/image.jpg)并NullPointerException
在该行抛出 a Log.i("MY_TAG", "Height: ... )
(images
是ArrayList
我的类的包含对象,它也包含 URL 和位图)。
感谢您的任何建议!