我的网站上有一张图片,我想在我的 ImageView 上设置它。为此,我需要使用异步任务。我正在像下面那样做。但是
new getThumbnail().execute(stringThumbnail);
正在向我抛出错误getThumbnail cannot be resolved to a type
。我在这里做错了什么?
final ImageView thumbnail = (ImageView) findViewById(R.id.btnThumbnail);
String stringThumbnail = "myImage.jpg";
new getThumbnail().execute(stringThumbnail);
class getThumbnail extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... data) {
String thumb = data[0];
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://mySite.com/images/" + thumb).getContent());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Bitmap img) {
// TODO: check this.exception
// TODO: do something with the feed
thumbnail.setImageBitmap(img);
}
}