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 9258753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:29:13+00:00 2026-06-18T12:29:13+00:00

I am using XML parser to extract few things off a website and I

  • 0

I am using XML parser to extract few things off a website and I have the code inside an Asynctask. For some reason I keep getting the NullPointerException, why?

What’s causing the error, and how do you fix it? I appreciate your time.

This is the LogCat

02-08 23:34:08.835: E/AndroidRuntime(28103): FATAL EXCEPTION: main
02-08 23:34:08.835: E/AndroidRuntime(28103): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thenewlistivew/com.thenewlistivew.MainActivity}: java.lang.NullPointerException
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.os.Looper.loop(Looper.java:137)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.app.ActivityThread.main(ActivityThread.java:4511)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at java.lang.reflect.Method.invokeNative(Native Method)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at java.lang.reflect.Method.invoke(Method.java:511)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:976)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at dalvik.system.NativeStart.main(Native Method)
02-08 23:34:08.835: E/AndroidRuntime(28103): Caused by: java.lang.NullPointerException
02-08 23:34:08.835: E/AndroidRuntime(28103):    at com.thenewlistivew.MainActivity.onCreate(MainActivity.java:40)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.app.Activity.performCreate(Activity.java:4486)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
02-08 23:34:08.835: E/AndroidRuntime(28103):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
02-08 23:34:08.835: E/AndroidRuntime(28103):    ... 11 more

My AsyncTask Code:

private class ShowDialogAsyncTask extends AsyncTask<Void, Integer, Void> {
        ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

        @Override
        protected void onPreExecute() {
            // update the UI immediately after the task is executed
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... params) {

            XMLParser parser = new XMLParser();
            String xml = parser.getXmlFromUrl(URL); // getting XML from URL
            Document doc = parser.getDomElement(xml); // getting DOM element

            NodeList nl = doc.getElementsByTagName(KEY_SONG);
            // looping through all song nodes <song>
            for (int i = 0; i < nl.getLength(); i++) {
                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();
                Element e = (Element) nl.item(i);
                // adding each child node to HashMap key => value
                map.put(KEY_ID, parser.getValue(e, KEY_ID));
                map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
                map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
                map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
                map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));

                // adding HashList to ArrayList
                songsList.add(map);
            }

            return null;
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);

        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            list = (ListView) findViewById(R.id.list);

            // Getting adapter by passing xml data ArrayList
            adapter = new LazyAdapter(MainActivity.this, songsList);
            list.setAdapter(adapter);
        }
    }

OnCreate Method code

ListView list;
LazyAdapter adapter;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        new ShowDialogAsyncTask().execute();

        // Click event for single list row
        list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

            }
        });
    }
  • 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-06-18T12:29:15+00:00Added an answer on June 18, 2026 at 12:29 pm

    You have —

    list.setOnItemClickListener(new OnItemClickListener()

    but you never initialize list

    Move this line to your onCreate() —

    list = (ListView) findViewById(R.id.list);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have student.xml file and am parsing this file using SAX Parser and now
I have a problem with using the SAX parser to parse a XML file.
I want to extract attributes from an xml file using Sax Parser I am
Possible Duplicate: How to extract a node attribute from XML using PHP's DOM Parser
I have to parse a XML structure in JAVA using the SAX parser. The
How do you extract attributes from XML using NSXML parser?? Heres my xml: <item>
I'm using the TBXML Parser to parse some big xml file. The xml file
Possible Duplicate: How to extract a node attribute from XML using PHP’s DOM Parser
NOT USING A XML PARSER I want to get the contents of the XML
Possible Duplicate: Best XML Parser for PHP Using JAXB with Google Android I need

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.