title: Adding Bitmaps dynamically to gridview in android
body: <p>I am trying to add bitmap images in gridview but continuously getting exceptions. when i try to do this in layouts it works fine. I am unable to get it. Here is the code what i am doing is:</p>
  
  <pre><code>public class SampleActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      GridView gv=(GridView)this.findViewById(R.id.gv);
      Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
  
      for (int i=0;i&lt;3;i++)
      {
          for (int j=0;j&lt;3;j++)
          {
              ImageView iv= new ImageView(this);
          //  iv.setId(i);
              Bitmap bm=Bitmap.createBitmap(src,j*(src.getWidth()/2),j*(src.getHeight()/3),src.getWidth()/3,src.getHeight()/3);
              iv.setImageBitmap(bm);
              gv.addView(iv);
          }
      }
  }
  </code></pre>
  
  <p>Kindly Any help is welcome :))</p>