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

  • Home
  • SEARCH
  • 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 9075085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:47:17+00:00 2026-06-16T18:47:17+00:00

I have a thread, whit a for-loop that is going through a object of

  • 0

I have a thread, whit a for-loop that is going through a object of file paths to images in the gallery.
The code inside the thread is:

    for(int i=0;i<tellerList;i++){
        Log.e("Picture", x.get(i));


        TAG_PICTURE = x.get(i);

        Bitmap bitmap = BitmapFactory.decodeFile(TAG_PICTURE);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();

        double hoyde1 = bitmap.getHeight();
        double bredde1 = bitmap.getWidth();
        int hoyde = (int) (hoyde1 / 1.5);
        int bredde = (int) (bredde1 / 1.5);
        Bitmap bitmapfinal = Bitmap.createScaledBitmap(bitmap, bredde,hoyde, false);
        bitmapfinal.compress(Bitmap.CompressFormat.JPEG, 80, stream);
        byte[] byte_arr = stream.toByteArray();
        try {
            stream.close();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        String image_str = Base64.encodeToString(byte_arr,
                Base64.DEFAULT);

        // HTTP POST

        ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
        param.add(new BasicNameValuePair("tag", login_tag));
        param.add(new BasicNameValuePair("unique_id", in
                .getStringExtra(TAG_UID)));
        param.add(new BasicNameValuePair("picture_data", image_str));

        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(param));

            Log.e("Ferdig med å laste opp", "Ferdig");
        } catch (Exception e) {

            Log.e("log_tag", "Error in http connection " + e.toString());
        }

    }

The code executes. And the first image is successfully uploaded, but when the thread tries to run again it crashes. LogCat output is:

01-06 18:14:47.113: E/dalvikvm(5010): Out of memory: Heap Size=58531KB, Allocated=50243KB, Limit=65536KB
01-06 18:14:47.113: E/dalvikvm(5010): Extra info: Footprint=56483KB, Allowed Footprint=58531KB, Trimmed=3712KB
01-06 18:14:47.113: D/skia(5010): --- decoder->decode returned false
01-06 18:14:47.113: W/dalvikvm(5010): threadid=47: thread exiting with uncaught exception (group=0x40d782d0)
01-06 18:14:47.113: E/AndroidRuntime(5010): FATAL EXCEPTION: Thread-543
01-06 18:14:47.113: E/AndroidRuntime(5010): java.lang.OutOfMemoryError: (Heap Size=58531KB, Allocated=50244KB)
01-06 18:14:47.113: E/AndroidRuntime(5010):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
01-06 18:14:47.113: E/AndroidRuntime(5010):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:658)
01-06 18:14:47.113: E/AndroidRuntime(5010):     at 
android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:347)
01-06 18:14:47.113: E/AndroidRuntime(5010):     at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:430)
01-06 18:14:47.113: E/AndroidRuntime(5010):     at com.example.socializerfragments.PhotoUploadSelecter.run(PhotoUploadSelecter.java:96)
01-06 18:14:47.113: E/AndroidRuntime(5010):     at java.lang.Thread.run(Thread.java:864)

So one image works grate, more than one, not so much… Does anyone know what the solution to the problem might be?

Thanks!

  • 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-16T18:47:18+00:00Added an answer on June 16, 2026 at 6:47 pm

    The problem is BitmapFactory.decodeFile(BitmapFactory.java:347) as stated in logcat. There are a few solutions. First is to catch outofmemory , see this post for more information . You can also decrease the size of your bitmaps. A great sample can be found in the docs

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

Sidebar

Related Questions

I have a thread in Ruby. It runs a loop. When that loop reaches
I have a client program, inside that I have thread... myClient { myListener_In_a_THREAD( relevant
I have thread that runs loop. I need that loop to be run once
i have thread (working great ) that invoking method in singletone object like this:
I have thread where downloading xml file a this xml file i want to
I have a thread from a thread pool in a service that does quite
I have a thread that does the following: 1) Do some work 2) Wait
I am using some software that requires me to have thread safety disabled. I
i have thread pool that create threads each thread worker calculate some work and
You have two threads, a and b. Thread a is in a forever loop,

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.