我有一个ImageView的图像设置已经从一个URL获取的图像问题。 下面是用于转动URL成可绘制对象的方法:
private Drawable LoadImage(String url){
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src");
return d;
}catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}
下面是代码调用的方法:
Drawable drawable = LoadImage("www.myurl.com/image.jpg");
imageView.setImageDrawable(drawable); //here is where I think it goes wrong
它给了我一个空指针异常,但是当我在文本视图中显示drawable.toString()可变我得到的是这样的:
android.graphics.drawable.BitMapDrawable@43e5bb18
因此,它表明它没有返回null,当它试图吸取失败。 我缺少的东西表现还是有什么错我的代码?