我有以下课程:
class CargaImgsParaAmpliar extends AsyncTask<Void, Void, Bitmap> {
final ProgressDialog progressDialog = new ProgressDialog(imagen.this);
protected void onPreExecute() {
progressDialog.setTitle("");
progressDialog.setMessage("Cargando Imagen...");
progressDialog.show();
}
protected Bitmap doInBackground(Void... params) {
Bitmap mIcon1 = null;
URL url_value;
try {
url_value = new URL(StrUrl);
mIcon1 = BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mIcon1;
}
protected void onPostExecute(Bitmap imagen) {
m_imageView.setImageBitmap(urlImageToBitmap(StrUrl));
progressDialog.dismiss();
}
}
我正在 AsyncTask 中进行互联网放电过程,但它仍然给了我例外android.os.NetworkOnMainThreadException
。
我该如何解决这个问题?