×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Nov 2010
    Posts
    118

    Parse from res folder

    hi i want to parse and display a content of my xml file inside my res folder:

    this is my code:
    Code:
    InputStream is = getClass().getResourceAsStream("dictionary.xml");
            InputStreamReader isr = new InputStreamReader(is);
                    KXmlParser parser = new KXmlParser();
                    parser.setInput(isr);
    
                    parser.nextTag();
                    parser.require(XmlPullParser.START_TAG, null, "root");
                    while(parser.next() != XmlPullParser.END_DOCUMENT)
                    {
                        if(parser.getEventType() == XmlPullParser.START_TAG)
                        {
                            String asg = "start tag: " + parser.getName()+ "\n  Content:  " + parser.nextText();
                            Alert tae=new Alert(null,asg,null,AlertType.INFO);
                            Display.getDisplay(this).setCurrent(tae);
                        }
                    }
    
                    parser.require(XmlPullParser.END_TAG, null, "root");
    what seems to be the problem?
    what do i need to improve?
    please help me...thanks

  2. #2
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Parse from res folder

    at least the first line needs to be
    InputStream is = getClass().getResourceAsStream("/dictionary.xml");
    Note the "/" in front of the file name. This of course requires that the file is located inside in the MIDlet in the root directory. If it is in some other directory you need to include that in the url (like if the file is in "resources" folder the locator needs to be /resources/dictionary.xml)

    I did not yet check if the rest of the code is ok :-)

    Hartti

  3. #3
    Regular Contributor
    Join Date
    Nov 2010
    Posts
    118

    Re: Parse from res folder

    i put my xml file inside a new folder where my java file is found... what do u mean MIDlet in the root directory?
    Last edited by binsint; 2011-01-20 at 18:23.

  4. #4
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Parse from res folder

    When you package a MIDlet into a JAR file the classes, resources and all are zipped within a folder structure. You can see the structure if you open the JAR file with a ZIP extractor utility. Depending on your build settings the resource files are likely placed in "/" directory or "/res" directory inside the MIDlet. You need to use that exact locator when accessing those resource files.

    Did this make things any clearer for you?

    Hartti

Similar Threads

  1. RES Folder
    By binsint in forum Mobile Java General
    Replies: 3
    Last Post: 2011-01-07, 11:16
  2. How to include /res folder in the package
    By burinutit in forum Mobile Java General
    Replies: 2
    Last Post: 2009-11-24, 09:03
  3. Drawing on image in res folder
    By jules_ in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2009-09-16, 08:49
  4. Change res folder content
    By Dyvanu in forum Mobile Java General
    Replies: 5
    Last Post: 2008-12-01, 12:31
  5. Help locating resources from res folder
    By imational in forum Mobile Java General
    Replies: 6
    Last Post: 2006-05-11, 04:01

Posting Permissions

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