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

  • Home
  • SEARCH
  • 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 6194757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:21:02+00:00 2026-05-24T03:21:02+00:00

I have code written for Android 2.2 that is supposed to parse xml from

  • 0

I have code written for Android 2.2 that is supposed to parse xml from a webpage to a String. It works fine on an Android 2.2 emulator, but it gives me a NullPointerException on my Android 3.1 tablet. Here is the code:

Log.d("refreshMeta", "refreshing meta.");
            url = new URL("http://www.chineseoutreach.ca/media/Cstreaming.xml");
            URLConnection connection;
            connection = url.openConnection();

            HttpURLConnection httpConnection = (HttpURLConnection)connection;
            int responseCode = httpConnection.getResponseCode();

            if (responseCode == HttpURLConnection.HTTP_OK) {
                InputStream in = httpConnection.getInputStream();
                Log.d("Connection","connected");
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();

                Document dom = db.parse(in);
                Element docEle = dom.getDocumentElement();
                NodeList nl = docEle.getElementsByTagName("nowplaying");
                Element entry = (Element)nl.item(0);

                try {
                    Element eartist = (Element)entry.getElementsByTagName("artist").item(0);
                sartist = eartist.getFirstChild().getNodeValue();
                Log.d("Artist",sartist);
                }
                catch(NullPointerException e) {
                    sartist = "";
                    Log.d("Connection",e.toString());
                }

Log on Android 3:

refreshmeta: refreshing meta.

Connection: Connected

Connection: java.lang.NullPointerException

EDIT
This is the line that causes it.
Element eartist = (Element)entry.getElementsByTagName(“artist”).item(0);

Edit 2

07-28 13:10:01.483: ERROR/Null(6189): my message

07-28 13:10:01.483: ERROR/Null(6189): java.lang.NullPointerException

07-28 13:10:01.483: ERROR/Null(6189): at com.ciam.app.CiamInfoActivity.refreshMeta(CiamInfoActivity.java:280)

07-28 13:10:01.483: ERROR/Null(6189): at com.ciam.app.CiamInfoActivity.access$0(CiamInfoActivity.java:257)

07-28 13:10:01.483: ERROR/Null(6189): at com.ciam.app.CiamInfoActivity$2.run(CiamInfoActivity.java:123)
07-28 13:10:01.483: ERROR/Null(6189): at java.lang.Thread.run(Thread.java:1020)

I suspect that there are some differences between the way xml is parsed on android 2 and android 3. Any ideas? Thanks in advance.

  • 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-24T03:21:02+00:00Added an answer on May 24, 2026 at 3:21 am

    There is a small mistake in your code. I don’t really understand why it was working with android 2.1 emu, but it shouldn’t have. Your problem was that you were doing a dom.getDocumentElement(). That function will return the base tag of your xml file which is in this case “nowplaying”. And then you are doing a “docEle.getElementsByTagName(“nowplaying”);” over that.

    If you want to be sure to get “nowplaying”, you have to do a “dom.getElementsByTagName(“nowplaying”)”.

    Corrected version:

    Document dom = db.parse(in);
    Element docEle = (Element)dom.getElementsByTagName("nowplaying").item(0);
    Element eartist = (Element)docEle.getElementsByTagName("artist").item(0);
    Element etitle = (Element)docEle.getElementsByTagName("title").item(0);
    Log.d("Artist", eartist.getTextContent());
    Log.d("Title", etitle.getTextContent());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written code that automatically creates CSS sprites based on the IMG tags
I have written code that opens 16 figures at once. Currently, they all open
I have a code snippet written in PHP that pulls a block of text
I have some old code written in C for 16-bit using Borland C++ that
I have a custom class that I've written that extends ImageView (for Android Java).
I have written a small android app that grabs some data and displays it
I have written some code in Java that will decode a SHOUTcast stream and
I have written an android service, that I need to run in the background
i have code written in c++. its a console app that takes an input
I'm working on a video codec for OMAP3430. I already have code written in

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.