title: When I load an image in background, it works fine, crashes when I load it into an ImageView inside a ListView
body: <p>I am trying to load images in the background to populate the images in a ListView.
  If I load an image in the background and load it into an image that is not in the ListView it works fine.  When I try to load the bitmap in an ImageView that is in the ListView it crashes. </p>
  
  <p>This is what I do:</p>
  
  <ol>
  <li>Created a Subclass of the AsyncTask</li>
  <li>Overide the GetView in Iconic adpter.</li>
  <li>In <code>getView()</code>, get the ImageView to load the image into by 
  <code>(ImageView) findViewById(R.id.icon)</code>, where icon is a id in the xml file for the ListView</li>
  <li>start the background process by 
  <code>new MyBackground( (ImageView) findViewById(R.id.icon) ).execute()</code>
  it crashes when it tries to load the bitmap into <code>(ImageView) findViewById(R.id.icon)</code>
  Now if I try to load the background image into an ImageView that is not in the List it works fine, i.e <code>MyBackground( (ImageView) findViewById(R.id.MyImage) ).execute()</code></li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>class IconicAdapter extends ArrayAdapter {
      Activity context;
  
      IconicAdapter(Activity context) {
          super(context, R.layout.row, LinkName);
  
  
          this.context=context;
      }
  
      public View getView(int position, View convertView,
                                              ViewGroup parent) {
          LayoutInflater inflater=context.getLayoutInflater();
          View row=inflater.inflate(R.layout.row, null);
          TextView label=(TextView)row.findViewById(R.id.label);
          label.setText( LinkName.get(position));
          ImageView icon=(ImageView)row.findViewById(R.id.icon);
          icon.setImageResource(R.drawable.icon);
  
          //new MyBackground( (ImageView) findViewById(R.id.icon) ).execute();
      //  new MyBackground( (ImageView) findViewById(R.id.myimage) ).execute();
  
          return(row);
      }
  }
  
  class MyBackground extends AsyncTask&lt;Void, Void, Bitmap&gt;
  {
      int p1;
      String p2;
      ImageView myimage;
  //  @Override 
      public MyBackground(ImageView in )
      {
      //  super.MyBackground
          myimage=in;
      }
  
  
      @Override
         protected Bitmap doInBackground(Void... params) {
           HttpClient client = new DefaultHttpClient();
           try {
             String uri = "http://www.besttechsolutions.biz/icon.png";
             HttpGet request = new HttpGet(uri);
             HttpResponse response = client.execute(request);
             return BitmapFactory.decodeStream(response.getEntity().getContent());
           } catch (ClientProtocolException e) {
             e.printStackTrace();
           } catch (IOException e) {
             e.printStackTrace();
           }
           return null;
         }
  
      @Override
         protected void onPostExecute(Bitmap image) {
           if(image == null){
               Log.d("ted", "could not download image");
  //           Toast.makeText(Main.this, "Download failed", Toast.LENGTH_LONG).show();
           }
           else{
               // losd into ListView
              // this will crash if image is in the list vue
             myimage.setImageBitmap(image);
           }
         }
  
  };
  </code></pre>