×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    23

    Nokia SDK 1.1 for java get Null when read XML File

    I have a XML file

    <Smileys>
    <Smiley>
    <Key></Key>
    <Value>/Emoticon/smiley_1.png</Value>
    </Smiley>
    <Smiley>
    <Key>:~</Key>
    <Value>/Emoticon/smiley_2.png</Value>
    </Smiley>
    </Smileys>
    with a source code
    Vector tagVector = null;
    InputStream is = null;
    InputStreamReader isr = null;
    try {
    is = class.getResourceAsStream(Setting.EMOTICON_PATH);
    isr = new InputStreamReader(is, "utf-8");
    XMLParser myParser = new XMLParser();
    Element e = myParser.parse(isr);
    tagVector = e.getChildrenByTagName("Smiley");
    } catch (Exception ex) {
    return;
    }
    I got java.lang.NullPointerException on Nokia SDK 1.1 for java, but also all of sdk "S40_5th_Edition_SDK,S40_5th_Edition_SDK_Feature_Pack_1,S40_6th_Edition_SDK...." is not have error

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Nokia SDK 1.1 for java get Null when read XML File

    Hi thanhlnh,

    I couldn't reproduce the NullPointerException on neither Nokia SDK 1.1 nor S40_5th_Edition_SDK when I tested your code with LWUIT 1.5 and the following minor modifications:

    Code:
    		Vector tagVector = null;
    		InputStream is = null;
    		InputStreamReader isr = null;
    		try { 
    			is = getClass().getResourceAsStream("file.xml");
    			isr = new InputStreamReader(is, "utf-8");
    			XMLParser myParser = new XMLParser();
    			Element e = myParser.parse(isr);
    			tagVector = e.getChildrenByTagName("Smiley");
    			System.out.println("Size of Elements: " + tagVector.size());
    		} catch (Exception ex) {
    		return;
    		}
    The last print statement could be reached and I could get "Size of Elements: 2" on my console.

    I only copied pasted your xml file, called it file.xml and placed it in the res directory of my Eclipse's working project. Instead of using the instance class, I used the method getClass().

    This could be related to how Setting.EMOTICON_PATH is evaluated on runtime.
    Also ensure that you are using the latest version of LWUIT.

Similar Threads

  1. Replies: 2
    Last Post: 2011-01-25, 06:50
  2. Null pointer error in read video files
    By souhomura in forum Streaming and Video
    Replies: 0
    Last Post: 2009-07-28, 09:35
  3. Null pointer error in read video files
    By souhomura in forum Streaming and Video
    Replies: 0
    Last Post: 2009-07-28, 09:34
  4. read return null after first loop
    By ballj in forum Bluetooth Technology
    Replies: 0
    Last Post: 2006-01-15, 07:37
  5. Read File from java app
    By TuxedoMask in forum Mobile Java General
    Replies: 6
    Last Post: 2004-12-26, 15:15

Posting Permissions

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