×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    159

    Consuming more time to get data from textfile in j2me

    I am workingo on nokia sdk2.0 using lwuit1.5 . I am getting data from textfile save res folder in my project .But it take some time during reading data .My code is given below
    Code:
    InputStream is = getClass().getResourceAsStream("/" + year + ".txt");
     XMLParser xm = new XMLParser();
     Element e = xm.parse(new InputStreamReader(is));
    int  len = e.getNumChildren();
      for (int i = 0; i < len; i++) 
    	                {
    	                	   
    	                    Element x = e.getChildAt(i);
    	                   System.out.println("e.getChildAt  "+i);
    	                    sp.setSubject(x.getChildAt(2).getChildAt(0).toString().replace('\'', ' ').trim());
    	                   v1.addElement(sp.getSubject());
    	                   sp.setstory(x.getChildAt(3).getChildAt(0).toString().replace('\'', ' ').trim());
    	                    v2.addElement(sp.getstory());
    	                }
    I am set data in setmethod in another class and get data from getmethod and store in vector.
    Many time i get the exception of "Uncaught exception java/lang/OutOfMemoryError"
    how i can do it properly with in time.
    Last edited by vikranttanwar@; 2013-11-25 at 10:33.

  2. #2
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    271

    Re: Consuming more time to get data from textfile in j2me

    How much data is in that file ? With limited heap size, it may be hard to solve this problem if the data set is huge. You could try setting things to null whenever possible.

    Worst case scenario,you could try compromising with performance.

    Save the subjects alone in memory and load the stories dynamically from a text file.(I assume the subjects wont be big enough to cause an OOM error)

    Alternatively,break down the contents of the text file to multiple text files.Each text file has a couple of stories (say 100).Load the text file which has the data the user wants to see .If he navigates to a story which is in a different text file, show a loading dialog and load the corresponding text file.

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

    Re: Consuming more time to get data from textfile in j2me

    Depending on the size of the file, you might be able to avoid the memory issues simply by switching to SAX or pull parsing, as they are much more memory efficient than DOM.

  4. #4
    Registered User
    Join Date
    May 2013
    Posts
    159

    Re: Consuming more time to get data from textfile in j2me

    I have 12 text file in res folder . Each have approx size 120 kb.so how we can solve this problem.i want to inform you that when i start reading data from text file that time my runtime memory is -176716- and at ending it remain 15200. i used the following code for getting runtime memory
    Runtime r=Runtime.getRuntime();
    System.out.println("free memory is ////////"+r.freeMemory());
    Last edited by vikranttanwar@; 2013-11-26 at 07:07.

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

    Re: Consuming more time to get data from textfile in j2me

    If reading & parsing data from your text files are time consuming, I will recommend you to do only on first of the app on the target device and the store parsed data mapping to your UI needs in RMS... so that next time on-wards your app perform better - reading and displaying data from RMS instead of files every time.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

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

    Re: Consuming more time to get data from textfile in j2me

    Quote Originally Posted by vikranttanwar@ View Post
    I have 12 text file in res folder . Each have approx size 120 kb.so how we can solve this problem
    That's a huge amount of data, do you read all of the files to the memory when the app is starting, or are they different categories or such, where a file is parsed only after the user chooses the specific category?

    Parsing a single 120 kb file shouldn't really be a problem, at least if you use SAX or pull parser. However, if you need all the data to be accessible at once, using XML like this is probably just too time- and memory consuming. If I were you, I'd consider storing the stories in a binary file (you can create the file on desktop Java, just UTF8-encode each story text to a byte array, and append to the file), and have a separate index file with title and offset to the main file for each story. That way, you'll just need to read the index file at startup, and can load the actual stories when necessary, without going through the whole file.

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    686

    Re: Consuming more time to get data from textfile in j2me

    vikranttanwar@: i actually have the best solution for you regarding the long process time of your XML file with LWUIT 1.5
    I noticed that you are using LWUIT XML code, the LWUIT 1.5 xml code has major faults as it keep creating and concatinating Strings using + operand (i.e. "string1" + "string2") this (and also because its implemented with recursion) is very bad and creates the slowness that you have.
    your options are:
    * switch to LWUIT s40 (which i believe fixed this issue a while back after community suggestions)
    * use another XML library (i suggest kXML which is XML Pull base library)
    * download the LWUIT 1.5 source and fix the Strings heavy + operand use with String builder and recompile the code and use that
    Heard of DVLUP? Join here

  8. #8
    Registered User
    Join Date
    May 2013
    Posts
    159

    Re: Consuming more time to get data from textfile in j2me

    but due to text area scrolling issue in s40 we have to switch from s40 to lwuit 1.5.there is a big issue of textArea scrolling issue in s40 .so how we can use s40_with_theme

  9. #9
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    686

    Re: Consuming more time to get data from textfile in j2me

    I dont know which textArea scrolling issue your facing with lwuit for s40 so i cant comment on that, i havent came across such issue with my apps.
    Heard of DVLUP? Join here

Similar Threads

  1. Can we open a textfile and write some data in J2me
    By rajan701v in forum Mobile Java General
    Replies: 26
    Last Post: 2012-09-28, 08:31
  2. Sound playing consuming memory - J2ME, S40, 6212
    By andrew_d_mackenzie in forum Audio
    Replies: 2
    Last Post: 2010-09-26, 18:47
  3. read textfile in j2me
    By sweetgurl in forum Mobile Java General
    Replies: 2
    Last Post: 2010-04-26, 06:37
  4. How to send textfile using GPRS in J2ME
    By J2meDeveloper in forum Mobile Java General
    Replies: 7
    Last Post: 2009-06-22, 08:46
  5. Too time-consuming when importing big project using carbide c++
    By runforu in forum Tools and SDK Feedback (Closed)
    Replies: 0
    Last Post: 2007-12-27, 02:11

Posting Permissions

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