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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:24:21+00:00 2026-05-26T14:24:21+00:00

I have a problem that I am facing OuOfMemory Error while printing a string

  • 0

I have a problem that I am facing OuOfMemory Error while printing a string after encoding bytes into String through Base64 encoder. Here are the following Code related details:

Error Stack:

11-05 12:25:30.995: ERROR/AndroidRuntime(2660): FATAL EXCEPTION: main
11-05 12:25:30.995: ERROR/AndroidRuntime(2660): java.lang.OutOfMemoryError
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:89)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at java.lang.StringBuffer.<init>(StringBuffer.java:83)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at com.example.TestCryptoActivity.onCreate(TestCryptoActivity.java:54)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at android.os.Looper.loop(Looper.java:123)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at java.lang.reflect.Method.invokeNative(Native Method)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at java.lang.reflect.Method.invoke(Method.java:521)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-05 12:25:30.995: ERROR/AndroidRuntime(2660):     at dalvik.system.NativeStart.main(Native Method)

Code(The Last line of the code is responsible for the error):

File file = new File("/sdcard/E0022505.mp4");
        try {
               is = new FileInputStream(file);
        } catch (FileNotFoundException e2) {
               e2.printStackTrace();
        }
        byte[] fileData = new byte[2097152];
        int read = 0;
        while(read != fileData.length) {
           try {
            read += is.read(fileData, read, fileData.length - read);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bos.write(fileData,0,read);

        bytes = bos.toByteArray();
        StringBuffer strNew = new StringBuffer(Base64.encodeToString(fileData, 0));
        System.out.println("The bytes array:"+strNew);---> This line makes error
  • 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-26T14:24:21+00:00Added an answer on May 26, 2026 at 2:24 pm

    Removing those three lines that don’t do anything useful would at least avoid at least 2097152 bytes in memory :

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bos.write(fileData,0,read);
    bytes = bos.toByteArray();
    

    For the rest, this code causes the exception to happen, but it’s maybe because some other part of the code, executed before is too memory-hungry.

    Try using a profiler to detect where the memory is used.

    But storing a whole large byte array, along with its copy encoded in base64, in memory in an android program is of course a bad idea.

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

Sidebar

Related Questions

I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map
I have a problem that output string must be utf8-formatted, I am writing currently
I have a TTStyledText with a floating image. The problem that I am facing
I have a dropdown which i want to fill through jquery. Problem that i
I herewith a problem that i am facing while implementing PDF file in iPhone.
In a couple of scripts that I use I have problem that is intermittent.
I have a problem that confuses my users, being that although an item is
I have the problem that an specific step in Ant can only be executed
I have a problem that I would like have solved via a SQL query.
I have a problem that I feel is best implimented in a stand alone

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.