public Object fetch(String address) throws MalformedURLException,
IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
private Drawable ImageOperations(Context ctx, String url) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
return null;
} catch (IOException e) {
return null;
}
catch (Exception e)
{
return null;
}
}
try {
Drawable a =ImageOperations(this,"url"); imgView.setImageDrawable(a);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
这工作,但在罕见ocasions应用程序冻结由于“SocketException:ADRESS家人不支持协议”。有没有什么办法解决这一问题?由于问题加载图像
好吧,我试着用这个线程的第一个答案:http://stackoverflow.com/questions/3090650/android-loading-an-image-from-the-web-with-asynctask,但“DownloadImageTask” - 新的DownloadImageTask.execute(mChart);“在eclipse中获得红色,即使创建了该类。我错过了什么? – Johan 2011-01-12 12:45:10