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 8167341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:09:41+00:00 2026-06-06T20:09:41+00:00

I have a problem with this code: (The error is below the code) public

  • 0

I have a problem with this code:
(The error is below the code)

public class ChooseImage extends Activity
{

private static final int DELETE_DIALOG = 1; 

private Gallery gallery = null; 

private int selectedImageId; 


  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState); 
       gallery = new Gallery(this); 
      Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 
      String[] projection = { MediaStore.Images.Media._ID }; 
      String selection = null; 
      String[] selectionArgs = null; 
      String sortOrder = null; 
      Cursor cursor = managedQuery(uri, projection, selection, selectionArgs, sortOrder); 

      BitmapFactory.Options options=new BitmapFactory.Options();
      options.inSampleSize = 8;

      gallery.setAdapter(new CursorAdapter(this, cursor, true) { 

        public View newView(Context context, Cursor cursor, ViewGroup parent) { 
                int id = cursor.getInt(0); 
                ContentResolver cr = getContentResolver(); 
                Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id); 
                Bitmap image = null; 

        try { 
            image = MediaStore.Images.Media.getBitmap(cr, uri); 
        } catch (Exception e) { 
         Log.e("Error", "Error", e); 
        } 

            ImageView imageView = new ImageView(context); 
            imageView.setId(id); 
            imageView.setScaleType(ScaleType.CENTER_INSIDE); 

            imageView.setImageBitmap(image); 
            return imageView; 
       }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            // TODO Auto-generated method stub

        } 
      }); 

      LinearLayout linearLayout = new LinearLayout(this); 
      linearLayout.addView(gallery); 
      setContentView(linearLayout); 

  }
}

THE ERROR IS:

07-03 15:40:59.978: E/AndroidRuntime(887): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:469)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:712)
07-03 15:40:59.978: E/AndroidRuntime(887):  at com.entDan.imagefun.ChooseImage$1.newView(ChooseImage.java:58)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.widget.CursorAdapter.getView(CursorAdapter.java:182)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.widget.Gallery.makeAndAddView(Gallery.java:745)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.widget.Gallery.fillToGalleryRight(Gallery.java:697)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.widget.Gallery.trackMotionScroll(Gallery.java:372)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.widget.Gallery$FlingRunnable.run(Gallery.java:1366)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.os.Handler.handleCallback(Handler.java:587)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.os.Looper.loop(Looper.java:123)
07-03 15:40:59.978: E/AndroidRuntime(887):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-03 15:40:59.978: E/AndroidRuntime(887):  at java.lang.reflect.Method.invokeNative(Native Method)
07-03 15:40:59.978: E/AndroidRuntime(887):  at java.lang.reflect.Method.invoke(Method.java:521)
07-03 15:40:59.978: E/AndroidRuntime(887):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
07-03 15:40:59.978: E/AndroidRuntime(887):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-03 15:40:59.978: E/AndroidRuntime(887):  at dalvik.system.NativeStart.main(Native Method)
  • 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-06-06T20:09:43+00:00Added an answer on June 6, 2026 at 8:09 pm

    Your problem is simple: You display too many images at once.

    Your solution can be done in many different ways 🙂

    You could do like google play, only show some images, download new images when the user gets “near” them and slowly discard the old images from memory. Could also be a next page button etc. to load the next images.

    In general avoid showing too many bitmaps and remember to recycle/discard/ old bitmaps (often the system does this for you, but not in a long list etc.).

    Edit:
    You could look into googles lru cache which is available with the support library. Following link explains how lru cache works and other very important things about bitmap usage: link.

    But whole this subject is actually pretty complex to do properly ;( I’d recommend that you look into googles shelves sample (which can be hard to understand, but if you can manage it, you’ll really learn a lot).

    Using the lru cache together with getting the images only when they are needed (in getview/bindview etc.) would probably work for you.

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

Sidebar

Related Questions

I have this sample code ( below ), example1() method works with no problem,
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
Hi i have problem with this code, i found it on the internet and
i am a beginner and i have a problem : this code doesnt compile
I have a problem with this code right here: - (void)fetchedData:(NSData *)responseData { //parse
I'm a beginner with jdbc ... I have a problem running this code :
I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
I have a problem here with this code. I'm opening a socket, then listening
Im create this code to store page view in database, but i have problem
I have this code, but I have a problem. When I update but do

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.