我希望有人可以帮助我解决我一直遇到的问题。我正在使我的应用程序在高于 3.0 的版本上运行,因此我只能在 UI 线程上执行 GUI 任务。我有以下代码,我没有得到任何编译错误,但它不起作用。在日志中,我收到以下错误:
I/AndroidRuntime(464):注意:附加线程 'Binder Thread #3' 失败
谢谢您的帮助!
new DownloadImageTask().execute(imgURL); //imgURL is declared as string URL
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
protected void onPostExecute(Bitmap result) {
((ImageView) findViewById(R.id.imgCity)).setImageBitmap(bmp);
}
protected Bitmap doInBackground(String... params) {
return loadImage(params[0]);
}
}
public Bitmap loadImage(String poiURLimg) {
try {
URL ulrn = new URL(poiURLimg);
HttpURLConnection con = (HttpURLConnection) ulrn.openConnection();
InputStream is = con.getInputStream();
bmp = BitmapFactory.decodeStream(is);
if (null != bmp)
return bmp;
} catch (Exception e) {
}
return bmp;
}