title: findViewById returns NULL with imageView
body: <p>I have a <code>gridViewAdapter</code> class that creates a view when there is none and I set an Id to it. Here is the <code>getView()</code> section of that class:</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
      // Try to reuse the views
      ImageView view = (ImageView) convertView;
      boolean checked = (mCheckBox==null)?false:(((CheckBox)  mCheckBox).isChecked());
      // if convert view is null then create a new instance else reuse it
      if (view == null) {
          view = new ImageView(Context);
          Log.d("GridViewAdapter", "new imageView added");
          view.setId(R.id.iconImageView_id);
      }
      if(checked == true){
          isSdReadable();
          Log.i("GridViewAdapter", "checkbox is checked");
      } else {
          Log.i("GridView", "Icons not for use/checkbox not checked");
      }
      view.setImageResource(drawables.get(position));
      view.setScaleType(ImageView.ScaleType.CENTER_CROP);
      view.setLayoutParams(new android.widget.GridView.LayoutParams(70, 70));
      view.setTag(String.valueOf(position));
      return view;
  }
  </code></pre>
  
  <p>I have a <code>ids.xml</code> in the values section of my resources here:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
    &lt;item type="id" name="iconImageView_id"/&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>Then I am trying to get the <code>imageView</code> in another class here:</p>
  
  <pre><code>/// Let's save to a .jpg file ...
  File file = new File(mContext.getFilesDir().getAbsolutePath() + "/test2.jpg");
  FileOutputStream out;
  try
  {
      file.createNewFile();
      out = new FileOutputStream(file);
      appBmp.compress(Bitmap.CompressFormat.JPEG, 80, out);
      Log.i("AppInfoAdapter", "The icon for use in gridView is saved");
      out.close();
  
      // Load back the image file to confirms it works
      Bitmap bitmap = BitmapFactory.decodeFile( file.getAbsolutePath() );
      ImageView imageView1 = (ImageView)v.findViewById(R.id.iconImageView_id);
      imageView1.setImageBitmap( bitmap );
      Log.i("AppInfoAdapter", "The icon image has been set into the gridView");
  }
  </code></pre>
  
  <p>But I get a <code>NPE</code> on this line:</p>
  
  <pre><code>imageView1.setImageBitmap( bitmap ); 
  </code></pre>
  
  <p>telling me that the <code>imageView</code> is returning <code>null</code></p>
  
  <p>Why is this? How can I fix this?</p>
  
  <p>ADDED:</p>
  
  <p>I am getting the imageView in another adapter class here:</p>
  
  <pre><code>@Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      // get the selected entry
      final ResolveInfo entry = (ResolveInfo) mListAppInfo.get(position);
  
      // reference to convertView
      View v = convertView;
  
      // inflate new layout if null
      if (v == null) {
          LayoutInflater inflater = LayoutInflater.from(mContext);
          v = inflater.inflate(R.layout.layout_appinfo, null);
          Log.d("AppInfoAdapter", "New layout inflated");
      }
  
      // load controls from layout resources
      ImageView ivAppIcon = (ImageView) v.findViewById(R.id.ivIcon);
      TextView tvAppName = (TextView) v.findViewById(R.id.tvName);
      TextView tvPkgName = (TextView) v.findViewById(R.id.tvPack);
      final CheckBox addCheckbox = (CheckBox) v
              .findViewById(R.id.addCheckbox);
      Log.d("AppInfoAdapter", "Controls from layout Resources Loaded");
  
      // set data to display
      ivAppIcon.setImageDrawable(entry.loadIcon(mPackManager));
      tvAppName.setText(entry.activityInfo.loadLabel(mPackManager));
      tvPkgName.setText(entry.activityInfo.packageName);
  
      Log.d("AppInfoAdapter", "Data Set To Display");
      addCheckbox
              .setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
                      if (addCheckbox.isChecked()) {
                          System.out.println("Checked");
  
                          PackageManager pm = mContext.getPackageManager();
                          final int   DEST_IMAGE_WIDTH = 100;
                          final int DEST_IMAGE_HEIGHT = 100;
                          ApplicationInfo appInfo = mContext.getApplicationInfo();
                          Drawable appIcon = pm.getApplicationIcon(appInfo);
                          Bitmap appBmp  = Bitmap.createBitmap(DEST_IMAGE_WIDTH, DEST_IMAGE_HEIGHT, Config.ARGB_8888); 
  
                          // Creates a new canvas based on the image specification
                          // created just above.
                          Canvas canvas = new Canvas(appBmp);
                          // (optional) Fills the entire canvas
                          canvas.drawColor(Color.WHITE);
                          // You need to set bounds otherwise a 0,0 sized image would be drawn.
                          appIcon.setBounds(0, 0, DEST_IMAGE_WIDTH, DEST_IMAGE_HEIGHT);
                          appIcon.draw(canvas);
  
                          /// Let's save to a .jpg file ...
                          File file = new File(mContext.getFilesDir().getAbsolutePath() + "/test2.jpg");
                          FileOutputStream out;
                          try
                          {
                              file.createNewFile();
                              out = new FileOutputStream(file);
                              appBmp.compress(Bitmap.CompressFormat.JPEG, 80, out);
                              Log.i("AppInfoAdapter", "The icon for use in gridView is saved");
                              out.close();
  
                              // Load back the image file to confirms it works
                            Bitmap bitmap = BitmapFactory.decodeFile( file.getAbsolutePath() );
                            ImageView imageView1 = (ImageView)v.findViewById(R.id.iconImageView_id);
                            imageView1.setImageBitmap( bitmap );  
                            Log.i("AppInfoAdapter", "The icon image has been set into the gridView");
                          }
  
                          catch (FileNotFoundException e1)
                          {
                              e1.printStackTrace();
                          }
                          catch (IOException e2)
                          {
                              e2.printStackTrace();
                          }
  
  
                      } else {
                          System.out.println("Un-Checked");
                      }
  
                  }
              });
  
      // return view
      return v;
  }
  </code></pre>