×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    280

    Uncaught exception java/lang/OutOfMemoryError while adding in vectors

    I am working on s40.I am using following code. This is the parsing code and is running fine till 328 value of vector size but after that it is throwing out of memory error. If it is due to no space left in heap then how should i parse rest of the elements????


    XmlParser parser = null;
    ParseEvent event = null;
    String story_storypath = "";
    Vector v4=new Vector();

    try{
    String url="http://tandonindia.com/story_new_xml?user=1"; //url link (this link contains xml file with each elemnt containing long stories)
    HttpConnection hc = (HttpConnection)Connector.open(url);
    InputStream is = hc.openInputStream();
    Reader reader = new InputStreamReader(is);
    parser = new XmlParser(reader);
    boolean xmlParsingDone = false;
    while (!xmlParsingDone)
    {
    event = parser.read();
    ParseEvent pe;
    switch (event.getType())
    {
    case Xml.START_TAG:
    // Pick up Title for display
    String tagName = event.getName();

    if ("storypath".equals(tagName)) //getting story element from xml file
    {
    pe = parser.read();
    if(pe.getText()!=null)
    {
    story_storypath = pe.getText(); //getting values
    }
    else
    {
    story_storypath="null"; // checking for null values
    }
    System.out.println("TOTAL MEMORY "+Runtime.getRuntime().totalMemory()); //checking total memory
    System.out.println("FREE MEMORY "+Runtime.getRuntime().freeMemory()); //free memory side by side
    v4.addElement(story_storypath);
    System.out.println("sizeeeeeeeeeeeeeeeeeeeeee of storypath--list---------------"+v4.size());
    }
    break;
    case Xml.END_TAG:
    break;
    case Xml.END_DOCUMENT:
    xmlParsingDone = true;
    break;
    case Xml.TEXT:
    break;
    case Xml.WHITESPACE:
    break;
    default:
    }
    }
    System.out.println("sizeeeeeeeeeeeeeeeeeeeeee of storypath--list---------------"+v4.size());
    }
    catch (IOException ioe){

    System.out.println("XML Parsing Error: " + ioe.toString());
    ioe.printStackTrace();
    }finally
    {
    parser = null;
    }
    // TODO Auto-generated method stub
    }
    Last edited by Manpreet_Singh; 2013-06-28 at 06:13.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Uncaught exception java/lang/OutOfMemoryError while adding in vectors

    It is not the 328 which matters but the overall heap usage of the midlet. You can check the maximum heap size for the various models on the specifications page (Devices above, Device specifications, pick a model, open "Memory functions", and you will see that it ranges from 2-4 megabytes for most relevant Series 40 models, with the exception of the Nokia Asha 501, which says 5.
    You already have these totalMemory and freeMemory checks, what do they say?

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    280

    Re: Uncaught exception java/lang/OutOfMemoryError while adding in vectors

    Hi wizard_hu_

    I checked total memory and free memory as u can see in my code.
    When execution starts the values are as follows :
    TOTAL MEMORY 2097152
    FREE MEMORY 1947800

    and at the end before out of memory error the values
    TOTAL MEMORY 2097152
    FREE MEMORY 9580

    If heap size is full then what should i do as i have to store the data coming in vector(through parsing) and then in rms ? and i have to include all the data coming
    Last edited by Manpreet_Singh; 2013-06-28 at 11:40.

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

    Re: Uncaught exception java/lang/OutOfMemoryError while adding in vectors

    I think the XML is simply too big - I opened the URL in a browser and the size of the page is currently 1,166,455 bytes. Even without the out of memory issue, this may not be a good idea, as loading that of amount of data will take a long time on a 2G connection.

    If you can add new functionality to the server side, a good solution might be to have an API for downloading only the titles of all the stories when the app is started, and then loading each story on demand when the user actually wants to read it.

  5. #5
    Registered User
    Join Date
    May 2013
    Posts
    280

    Re: Uncaught exception java/lang/OutOfMemoryError while adding in vectors

    Thanks TongMuan

Similar Threads

  1. Replies: 4
    Last Post: 2012-10-11, 09:57
  2. Error: Uncaught exception java/lang/OutOfMemoryError
    By kumar1234567 in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2011-07-06, 12:32
  3. Replies: 3
    Last Post: 2011-03-25, 20:22
  4. SUDDENLY ... Uncaught exception java/lang/OutOfMemoryError
    By mbenz1 in forum Mobile Java General
    Replies: 1
    Last Post: 2008-03-15, 23:25
  5. Replies: 2
    Last Post: 2007-09-18, 08:47

Posting Permissions

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