我使用下面的类来下载一个图像,发送的url是正确的,但是url.getContext() 每次都返回null。问题出在哪里呢?
package com.WasserSportLotse;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import android.content.Context;
import android.graphics.drawable.Drawable;
class ImageDownloader {
private Drawable d;
public ImageDownloader(Context ctx, String url, String saveFilename) {
try {
InputStream is = (InputStream) this.fetch(url);
d = Drawable.createFromStream(is, "src");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public Drawable getImage(){
return d;
}
public Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
}