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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:23:06+00:00 2026-06-13T20:23:06+00:00

I am getting exception of out of memory in the below code. try {

  • 0

I am getting exception of out of memory in the below code.

try {
    String strBase64 = BitMapToString(bitmap);
    bitmap.recycle();
    JSONObject data = new JSONObject();
    data.put("image_data", strBase64.toString());
    data.put("uploadedBy", "1");
    Log.i("JSON DATA", data.toString());
    HttpClient httpClient = new DefaultHttpClient();
    String url = "http://**.**.***.***:91/bisqup/index.php?r=ws/AddAppImage";
    HttpPost httpPost = new HttpPost(url);
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    parameters.add(new BasicNameValuePair("data", data.toString()));
    httpPost.setEntity(new UrlEncodedFormEntity(parameters));
    HttpResponse response = httpClient.execute(httpPost);
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String json = reader.readLine();
    JSONTokener tokener = new JSONTokener(json);
    JSONObject finalResult = new JSONObject(tokener);
    Log.i("Response", "" + finalResult.toString());
} catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
}

public String BitMapToString(Bitmap bitmap) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
        byte[] b = baos.toByteArray();
        String temp = Base64.encodeToString(b, Base64.DEFAULT);
        baos.close();
        baos = null;
        Log.i("BASE64", temp);
        return temp;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}

unfortunately I am getting the exaception like this.

11-05 20:28:05.414: E/AndroidRuntime(23446): FATAL EXCEPTION: main
11-05 20:28:05.414: E/AndroidRuntime(23446): java.lang.OutOfMemoryError
11-05 20:28:05.414: E/AndroidRuntime(23446):    at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:140)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at java.lang.StringBuilder.append(StringBuilder.java:125)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at org.json.JSONStringer.string(JSONStringer.java:344)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at org.json.JSONStringer.value(JSONStringer.java:252)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at org.json.JSONObject.writeTo(JSONObject.java:667)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at org.json.JSONObject.toString(JSONObject.java:636)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at com.siliconithub.android.bisqup.BisqupImagePreview$2.onClick(BisqupImagePreview.java:134)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at android.view.View.performClick(View.java:2485)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at android.view.View$PerformClick.run(View.java:9080)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at android.os.Handler.handleCallback(Handler.java:587)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at android.os.Looper.loop(Looper.java:130)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at android.app.ActivityThread.main(ActivityThread.java:3687)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at java.lang.reflect.Method.invokeNative(Native Method)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at java.lang.reflect.Method.invoke(Method.java:507)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-05 20:28:05.414: E/AndroidRuntime(23446):    at dalvik.system.NativeStart.main(Native Method)

So can anyone tell me why this memory issue is rising with this code?

Any suggestion will be appreciated.

  • 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-13T20:23:08+00:00Added an answer on June 13, 2026 at 8:23 pm

    Try generating your JSON object without the JSONObject class, it seems fairly simple, so just build the string.

    String data = "{ image_data: \"" + strBase64.toString() + "\", uploadedBy: \"1\" }";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting Out of memory exception when assigning values in session variables. The
....... I keep getting that nasty out of memory exception, for which I plan
I am getting an intermittent out of memory exception at this statement: return ms.ToArray();
I'm getting an out of memory exception on this loop...however, it never even reaches
I am getting an out of memory exception when using a time. Could it
We have a project that is getting an Out of memory exception. I'm trying
Getting Out of memory error while loading large string from the server. This is
I'm trying out an implementation of QuickSort but getting an Exception in thread main
I'm getting a 'The index 0 is out of range' exception in the following
i'm getting exception on Transformer transformer = tFactory.newTransformer(StreamXSL); but the error below is not

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.