Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7444335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:29:18+00:00 2026-05-29T11:29:18+00:00

I am trying to parse an XML file. This is the file: <root> <entry>

  • 0

I am trying to parse an XML file. This is the file:

<root>
        <entry>
                <username>achanda</username>
                <latitude>45.123</latitude>
                <longtitude>76.345</longtitude>
                <timestamp>2000</timestamp>
                <filename>image2.jpg</filename>
        </entry>
        <entry>
                <username>achanda</username>
                <latitude>45.123</latitude>
                <longtitude>76.345</longtitude>
                <timestamp>2000</timestamp>
                <filename>image2.jpg</filename>
        </entry>
        <entry>
                <username>achanda</username>
                <latitude>45.123</latitude>
                <longtitude>76.345</longtitude>
                <timestamp>2000</timestamp>
                <filename>image2.jpg</filename>
        </entry>
</root>

This is the code:

private String getTextValue(Element ele, String tagName) {
        String textVal = "";
        NodeList nl = ele.getElementsByTagName(tagName);
        if (nl != null && nl.getLength() > 0) {
            Element el = (Element) nl.item(0);
            Node n = el.getFirstChild();
            //TODO this line throws an exception for the last
            //entry in the xml file. Fix this
            textVal = n.getNodeValue();
        }
        return textVal;
    }

This parses the file for the first two <entry> tags but getNodeValue() returns null for the last tag. I found here that it’s supposed to return null in some conditions. How do I extract the fields then? I tried casting el.getFirstChild() to Element, even that did not work.

    private float getFloatValue(Element ele, String tagName) {
        return Float.parseFloat(getTextValue(ele, tagName));
    }

    public ArrayList<GeoPoint> parseFile(String path) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        Document dom = null;
        ArrayList<GeoPoint> gp = new ArrayList<GeoPoint>();
        try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            dom = db.parse(path);

            org.w3c.dom.Element eroot = dom.getDocumentElement();
            NodeList nl = eroot.getElementsByTagName("entry");

            if (nl != null && nl.getLength() > 0) {
                for (int i = 0; i < nl.getLength(); i++) {
                    org.w3c.dom.Element el = (org.w3c.dom.Element) nl.item(i);
                    float lat = (float) (getFloatValue(el, LAT) * 1E6);
                    float lon = (float) (getFloatValue(el, LON) * 1E6);
                    Log.e("###LAT: ", Float.toString(lat));
                    Log.e("###LON: ", Float.toString(lon));
                    //gp.add(new GeoPoint((int) lat, (int) lon));
                }
            }
        } catch (ParserConfigurationException pce) {
            pce.printStackTrace();
        } catch (SAXException se) {
            se.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        return gp;
    }

Logcat output:

12-08 01:05:38.718: D/AndroidRuntime(3148): Shutting down VM
12-08 01:05:38.718: W/dalvikvm(3148): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-08 01:05:38.779: E/AndroidRuntime(3148): FATAL EXCEPTION: main
12-08 01:05:38.779: E/AndroidRuntime(3148): java.lang.IllegalStateException: Could not execute method of the activity
12-08 01:05:38.779: E/AndroidRuntime(3148):     at android.view.View$1.onClick(View.java:2144)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at android.view.View.performClick(View.java:2485)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at android.view.View$PerformClick.run(View.java:9080)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at android.os.Handler.handleCallback(Handler.java:587)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at android.os.Looper.loop(Looper.java:130)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at android.app.ActivityThread.main(ActivityThread.java:3683)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at java.lang.reflect.Method.invokeNative(Native Method)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at java.lang.reflect.Method.invoke(Method.java:507)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at dalvik.system.NativeStart.main(Native Method)
12-08 01:05:38.779: E/AndroidRuntime(3148): Caused by: java.lang.reflect.InvocationTargetException
12-08 01:05:38.779: E/AndroidRuntime(3148):     at java.lang.reflect.Method.invokeNative(Native Method)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at java.lang.reflect.Method.invoke(Method.java:507)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at android.view.View$1.onClick(View.java:2139)
12-08 01:05:38.779: E/AndroidRuntime(3148):     ... 11 more
12-08 01:05:38.779: E/AndroidRuntime(3148): Caused by: java.lang.NullPointerException
12-08 01:05:38.779: E/AndroidRuntime(3148):     at com.apps.terrapin.SearchActivity.getTextValue(SearchActivity.java:186)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at com.apps.terrapin.SearchActivity.getFloatValue(SearchActivity.java:192)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at com.apps.terrapin.SearchActivity.parseFile(SearchActivity.java:209)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at com.apps.terrapin.SearchActivity.searchData(SearchActivity.java:100)
12-08 01:05:38.779: E/AndroidRuntime(3148):     at com.apps.terrapin.SearchActivity.searchClicked(SearchActivity.java:70)
12-08 01:05:38.779: E/AndroidRuntime(3148):     ... 14 more

Update
This issue was resolved once I deleted all contents of the xml file and wrote it again. It seems that Android was caching the file somehow. What else could have been a problem here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:29:22+00:00Added an answer on May 29, 2026 at 11:29 am

    This issue was resolved once I deleted all contents of the xml file and wrote it again. It seems that Android was caching the file somehow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am beginner in PHP. I am trying to parse this xml file. <relationship>
So I'm trying to parse an xml file: <?xml version=1.0 encoding=utf-8 ?> <Root> <att1
I am trying to parse this XML file with this type of layout: <POX>
I am trying to parse this XML file for a school project: http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/genre=20/xml .
i'm trying to parse this xml file but i can't find a way to
I'm trying to parse a XML file using TBXML . However, this parser has
I'm trying to parse an xml file that contains accents, but I get this
I am trying to parse this xml file, which has some nested nodes. I
I'm getting this error (see title) while trying to parse an XML file in
I have an XML file that I'm trying to parse with Linq-to-XML. One of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.