誰かが私が抱えていた問題を解決してくれることを願っています。私は自分のアプリを 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;
}