Problems creating Image Gallery using file paths not drawable images
<p>So I'm trying to build a gallery that displays images from a folder on the SD card not images in my drawable folder. I have an array of the file paths and I'm trying to use the file <code>uri</code> from each image in the gallery but I get a run time error that crashes the app at this line:</p>

<p><code>iView.setImageURI(Uri.fromFile(new File(files.get(arg0))));</code></p>

<p>Here is part of the error in LogCat: (it was huge so I didn't include the entire thing)</p>

<pre><code>12-30 14:26:56.600: E/AndroidRuntime(4995): FATAL EXCEPTION: main
12-30 14:26:56.600: E/AndroidRuntime(4995): java.lang.OutOfMemoryError
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:738)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.graphics.drawable.Drawable.createFromStream(Drawable.java:698)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.widget.ImageView.resolveUri(ImageView.java:530)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.widget.ImageView.setImageURI(ImageView.java:314)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at com.cp.Media$ImageAdapter.getView(Media.java:174)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.widget.Gallery.makeAndAddView(Gallery.java:748)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.widget.Gallery.fillToGalleryRight(Gallery.java:700)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.widget.Gallery.layout(Gallery.java:631)
12-30 14:26:56.600: E/AndroidRuntime(4995):     at android.widget.Gallery.onLayout(Gallery.java:339)
</code></pre>

<p>Below is my code, Does someone have any idea what I'm doing wrong?</p>

<pre><code>    ImageSwitcher iSwitcher;
    private ArrayList&lt;String&gt; files = new ArrayList&lt;String&gt;();
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    setContentView(R.layout.media);
     files.add("/mnt/sdcard/DCIM/Camera/IMG_20111124_130713.jpg");
            files.add("/mnt/sdcard/DCIM/Camera/IMG_20111031_072817.jpg");
            files.add("/mnt/sdcard/DCIM/Camera/IMG_20111031_072750.jpg");
    iSwitcher = (ImageSwitcher) findViewById(R.id.ImageSwitcher01);
            iSwitcher.setFactory(this);
            iSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
                    android.R.anim.fade_in));
            iSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
                    android.R.anim.fade_out));

            Gallery gallery = (Gallery) findViewById(R.id.Gallery01);
            gallery.setAdapter(new ImageAdapter(this));
            gallery.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
                        long arg3) {
                    //iSwitcher.setImageResource(Uri.fromFile(new File(files.get(arg2))));
                    iSwitcher.setImageURI(Uri.fromFile(new File(files.get(arg2))));
                }
            });
    }

    public class ImageAdapter extends BaseAdapter {

            private Context ctx;

            public ImageAdapter(Context c) {
                ctx = c; 
            }

            @Override
            public int getCount() {

                return files.size();
            }

            @Override
            public Object getItem(int arg0) {

                return arg0;
            }

            @Override
            public long getItemId(int arg0) {

                return arg0;
            }

            @Override
            public View getView(int arg0, View arg1, ViewGroup arg2) {

                ImageView iView = new ImageView(ctx);

//THE LINE BELOW IS THE LINE THAT CAUSES THE ERROR IN LOGCAT
                iView.setImageURI(Uri.fromFile(new File(files.get(arg0))));
                iView.setScaleType(ImageView.ScaleType.FIT_XY);
                iView.setLayoutParams(new Gallery.LayoutParams(150, 150));
                return iView;
            }

        }

        @Override
        public View makeView() {
            ImageView iView = new ImageView(this);
            iView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            iView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
            iView.setBackgroundColor(0xFF000000);
            return iView;
        }
</code></pre>
