title: Unable to display images into Gridview using Universal Image Loader?
body: <p>I am trying to display images from <code>sdcard</code> and <code>drawable</code> inside <code>gridview</code> using the following code.But it doesn't works.It crashes in <code>Galaxy Note</code> due to <code>Memory Error</code> but displaying wrong images in <code>emulator</code>  and also takes alot of time to display them.</p>
  
  <pre><code>DisplayImageOptions options = new DisplayImageOptions.Builder()
  .cacheInMemory().cacheOnDisc()
  .bitmapConfig(Bitmap.Config.RGB_565).build();
  </code></pre>
  
  <p><strong>Adapter Class</strong></p>
  
  <pre><code> public class GridAdapter extends BaseAdapter {
  
      public GridAdapter(Context ctx) {
          // TODO Auto-generated constructor stub
  
          imageLoader = ImageLoader.getInstance();
          imageLoader.init(ImageLoaderConfiguration.createDefault(ctx));
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return mImages.size();
      }
  
      @Override
      public Object getItem(int pos) {
          // TODO Auto-generated method stub
          return mImages.get(pos);
      }
  
      @Override
      public long getItemId(int arg0) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      public class ViewHolder {
  
          ImageView image;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
  
          ViewHolder holder;
  
          if (convertView == null) {
  
              holder = new ViewHolder();
  
              convertView = getLayoutInflater().inflate(R.layout.grid_image,
                      parent, false);
              holder.image = (ImageView) convertView
                      .findViewById(R.id.gridImage);
              holder.image.setLayoutParams(new LinearLayout.LayoutParams(
                      width / 2, width / 2));
              convertView.setTag(holder);
  
          } else {
  
              holder = (ViewHolder) convertView.getTag();
          }
  
          if (mImages.get(position).getImageSource().equals("sdcard")) {
  
              imageLoader.displayImage(mImages.get(position).getImages(),
                      holder.image,options);
          } else {
  
              String url = "drawable://"
                      + Integer.parseInt(mImages.get(position).getImages());
  
              imageLoader.displayImage(url, holder.image,options);
  
          }
  
          return convertView;
      }
  }
  </code></pre>
  
  <p><strong>Update :</strong> I have around 30 images in gridview, at the beginning it just displays first image all over the place and it takes around 1 minute to display all the images correctly.</p>
  
  <p><strong>Logcat</strong></p>
  
  <pre><code>04-16 21:41:16.522: E/dalvikvm-heap(738): Out of memory on a 1042024-byte allocation.
  04-16 21:41:16.565: I/dalvikvm(738): "pool-1-thread-1" prio=4 tid=15 RUNNABLE
  04-16 21:41:16.565: I/dalvikvm(738):   | group="main" sCount=0 dsCount=0 obj=0x4054f720 self=0x279080
  04-16 21:41:16.572: I/dalvikvm(738):   | sysTid=762 nice=10 sched=0/0 cgrp=bg_non_interactive handle=2593208
  04-16 21:41:16.591: I/dalvikvm(738):   | schedstat=( 47274229556 127781868212 1951 )
  04-16 21:41:16.591: I/dalvikvm(738):   at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:~91)
  04-16 21:41:16.591: I/dalvikvm(738):   at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
  04-16 21:41:16.591: I/dalvikvm(738):   at android.graphics.Bitmap.nativeCompress(Native Method)
  04-16 21:41:16.633: I/dalvikvm(738):   at android.graphics.Bitmap.compress(Bitmap.java:589)
  04-16 21:41:16.642: I/dalvikvm(738):   at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromDrawable(BaseImageDownloader.java:188)
  04-16 21:41:16.642: I/dalvikvm(738):   at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:92)
  04-16 21:41:16.642: I/dalvikvm(738):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.downloadImage(LoadAndDisplayImageTask.java:340)
  04-16 21:41:16.652: I/dalvikvm(738):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryCacheImageOnDisc(LoadAndDisplayImageTask.java:307)
  04-16 21:41:16.652: I/dalvikvm(738):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:249)
  04-16 21:41:16.652: I/dalvikvm(738):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:131)
  04-16 21:41:16.652: I/dalvikvm(738):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  04-16 21:41:16.713: I/dalvikvm(738):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  04-16 21:41:16.713: I/dalvikvm(738):   at java.lang.Thread.run(Thread.java:1019)
  </code></pre>