×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    java.lang.OutOfMemoryError

    Hello Guys,

    I have problem, when i encode the image byte array with Base64 method. The Base64 i've use is from bouncy castle here: http://www.bouncycastle.org/java.html. The Base64 encode is return byte[] array. After i got the Base64 encode then i put it on the string. After that the error message: java.lang.OutOfMemoryError. I investigate, this is because the result of Base64 is too large. So, the String can not hold, and this is because the limit of KVM. For your information, i am developing application for S40 with J2ME. Somebody can help or give me advice to solve this issue...?.

    Here is my code chunk

    Code:
    // this.sendImage is the byte[] array cause the encode returning the byte array.
    this.sendImage = Base64.encode(sendImage);
    String tmp = new String(sendImage);


    Best Regards,
    Iqbal

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: java.lang.OutOfMemoryError

    Quote Originally Posted by muhamad.iqbal View Post
    Hello Guys,

    I have problem, when i encode the image byte array with Base64 method. The Base64 i've use is from bouncy castle here: http://www.bouncycastle.org/java.html. The Base64 encode is return byte[] array. After i got the Base64 encode then i put it on the string. After that the error message: java.lang.OutOfMemoryError. I investigate, this is because the result of Base64 is too large. So, the String can not hold, and this is because the limit of KVM. For your information, i am developing application for S40 with J2ME. Somebody can help or give me advice to solve this issue...?.

    Here is my code chunk

    Code:
    // this.sendImage is the byte[] array cause the encode returning the byte array.
    this.sendImage = Base64.encode(sendImage);
    String tmp = new String(sendImage);
    Best Regards,
    Iqbal
    As the byte[] created by the image data encoded in base64 is very large, it cannot be stored in a string type variable. If you wish to send it to Recordstore or server or filesystem - directly push the byte[] to I/O for required action.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

    Re: java.lang.OutOfMemoryError

    Iqbal, the picture is in memory/heap several times with our approach, at least three times. How large is the original picture? Why do you want to Base64 it at all? Perhaps there is an alternative.

  4. #4
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: java.lang.OutOfMemoryError

    Tradu,

    My picture size is 100 kb, and why i want to Base64 it?. It because the rule on the server.The server need me to encode the picture into Base64 before i send it. I don't know exactly the reason why server need me to Base64. And What is the alternative way..?.



    Best Regards,
    Iqbal

  5. #5
    Registered User
    Join Date
    May 2008
    Location
    Surat Thani
    Posts
    260

    Re: java.lang.OutOfMemoryError

    Quote Originally Posted by muhamad.iqbal View Post
    My picture size is 100 kb, and why i want to Base64 it?. It because the rule on the server.The server need me to encode the picture into Base64 before i send it. I don't know exactly the reason why server need me to Base64. And What is the alternative way..?.
    l
    How about encoding the image directly to the OutputStream of your HTTP request? If Bouncy Castle doesn't support this, you can always write your own Base64 implementation that does.

  6. #6
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: java.lang.OutOfMemoryError

    No, TongMuan i use xmpp not http. For now i can send 200Kb image but without Base64 encoding just send the byte[] array.

  7. #7
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: java.lang.OutOfMemoryError

    Ok amitabh i just replace without encoding just send the byte[] array.

  8. #8
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: java.lang.OutOfMemoryError

    Quote Originally Posted by im2amit View Post
    As the byte[] created by the image data encoded in base64 is very large, it cannot be stored in a string type variable. If you wish to send it to Recordstore or server or filesystem - directly push the byte[] to I/O for required action.
    Hi Amitabh,

    How much the byte[] maximum size can be hold with String()..??


    Best Regards,
    Iqbal

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,691

    Re: java.lang.OutOfMemoryError

    There is no API limit you would have to worry about (32-bit signed, meaning 2 gigabytes minus 1 byte for byte[] and 2 gigacharacters minus 1 character for String). OutOfMemoryError comes much sooner as you already experience.

  10. #10
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: java.lang.OutOfMemoryError

    Hai All,

    Thank you for your help. So, now the server change the protocol from xmpp to http for just send the media. So, i don't use base64 anymore but directly hit to http by multipart.

Similar Threads

  1. Java/lang/OutofMemoryError
    By samuelo12337@yahoo.com in forum General Development Questions
    Replies: 1
    Last Post: 2012-07-23, 07:05
  2. java.lang.OutOfMemoryError
    By csckid in forum Mobile Java Media (Graphics & Sounds)
    Replies: 27
    Last Post: 2010-09-18, 19:26
  3. lcdui.Image.createImage -> java.lang.OutOfMemoryError: Java heap space
    By sbmcdeshan in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2009-02-23, 19:29
  4. java.lang.OutOfMemoryError
    By Panta in forum Mobile Java General
    Replies: 10
    Last Post: 2008-06-20, 13:06
  5. java.lang.OutOfMemoryError
    By slatanx in forum Mobile Java General
    Replies: 2
    Last Post: 2004-08-24, 07:14

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×