×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    2

    outofmemory exception

    Hi im new in j2me programming...
    im writting a program to download documents from a server... the server send a string with the base64 code (xml-rpc)of the document.. i save that string in a StringBuffer but when the Buffer has a 1117527 lenght an outofmemoryexception is thrown...
    what can i do to to save memory?.
    i proved my code in a nokia n80 and the exception is thrown in that lenght.. in a nokia n82 i can download even more...

    this is the code:

    do{
    //execute request


    start = System.currentTimeMillis();
    obj = request.execute();
    end = System.currentTimeMillis();

    //calculate next page size
    //dataSize = calcSize>pingSize?calcSizeingSize;


    if(obj instanceof Hashtable){
    response = new DocumentResponse((Hashtable)obj);
    //Refresh the indexes for new request
    request.setFrom(response.getTo());//new calculated From;
    request.setTo(response.getTo()+(int)dataSize);//new calculated To;
    if(x==1){
    System.out.println("SET");
    this.data.setData(response.getData());
    }
    else{
    System.out.println("add");
    this.data.addData(response.getData());

    }
    }
    x++;
    System.gc();
    //moveToStore();
    System.out.println(data.getLength());
    }while(!response.hasMore());

    done = true;
    System.out.println(data.getLength());
    moveToStore(); //move the document downloaded to a permanent localization and remove partial download



    the adddata and setdata functions :

    public void setData(String data){
    this.data = data;
    sb = new StringBuffer(this.data);
    }

    public void addData(String data){
    this.data = data;
    sb.append(this.data);


    }



    can anyone help me???

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: outofmemory exception

    Hi Luischester,

    1117527 bytes are quite a lot for a J2ME application. You should try to break that download in more parts, if your application allows it.

    Practically, you could try to download first part of data and use it (save it, in your case), than proceed with another chunk of data and use it, and so on...

    Hope it helps
    Pit

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    2

    Re: outofmemory exception

    Hi Jappit.. in fact i tried to save data instead of adding to the StringBuffer... with the FileConnection API.. but with every chunk data the API Ask if the user allows to read and Write.. so if i want to save an image of 1 mb in the SD Card.. the user need to sey "yes" about 5 o 6 times.. and thats not "nice" to the final user...

    i read about to avoid those question i need to sign the application.. but i dont find where or how... and maybe that could be a good solution dont u think?

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: outofmemory exception

    About the multiple user prompts, this is a behaviour that changes from phone to phone: you can have many (as in your case) or only one prompt for each application usage. Which phone gives you these multiple prompts?

    If you want to sign your application with a certificate, you can buy it from different Certificate Authorities, like Verisign or Thawte. There is a lot of documentation about signing on this forum, but little hints on them:

    * they're not free, even for development purposes (only motorola, as far as I know, allows free development signing for a limited time)
    * every phone has its own certificates, so you must know which certificates your target phones support..
    * there is not a common behaviour on all phones: that is, there is not a guarantee that on your phone a certificate will totally eliminate prompts for file connections

    Anyway, if you're new to J2me programming, my hint is to avoid signing for these first steps, so you'll have clearer ideas after some tests on different phones.

    Cheers,
    Pit

Similar Threads

  1. s60 3rd ed emulator crash
    By Kimau in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2008-06-18, 22:12
  2. outOfMemory exception on device with 2mb memory
    By gx in forum Mobile Java General
    Replies: 6
    Last Post: 2007-05-24, 10:33
  3. VS.Net 2003 Carbide 2.01 and epoc32.exe
    By ValentinK in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2007-01-12, 12:31
  4. how to avoid OutofMemory Exception
    By lakshmanraob in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2005-10-28, 14:53
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

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