Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:50:42+00:00 2026-05-27T23:50:42+00:00

So I’m trying to build a gallery that displays images from a folder on

  • 0

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 uri from each image in the gallery but I get a run time error that crashes the app at this line:

iView.setImageURI(Uri.fromFile(new File(files.get(arg0))));

Here is part of the error in LogCat: (it was huge so I didn’t include the entire thing)

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)

Below is my code, Does someone have any idea what I’m doing wrong?

    ImageSwitcher iSwitcher;
    private ArrayList<String> files = new ArrayList<String>();
        @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<?> 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;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:50:42+00:00Added an answer on May 27, 2026 at 11:50 pm

    the idea is to create a lighter bitmap from the file you have on the sdcard. take a look a this link: http://www.stackoverflow.com/a/823966/935075

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.