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