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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:58:03+00:00 2026-06-06T23:58:03+00:00

Im parsing an xml file and i keep getting a nullpointer exception. I don’t

  • 0

Im parsing an xml file and i keep getting a nullpointer exception. I don’t know here the null pointer is 🙁

ListView.java

static String URL = "https://dl.dropbox.com/u/####/wosm-library-EN.xml";    
static final String KEY_ITEM = "item"; 
static final String KEY_ID = "id";
static final String KEY_TITLE = "title";
static final String KEY_DESCRIPTION = "description";
static final String KEY_FILESIZE = "filesize";
static final String KEY_THUMB_URL = "thumb_url";
static final String KEY_DOCUMENT_URL = "document_url";
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);



ListView list;
LazyAdapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.library);

    sharedPrefs.getBoolean("french", false); {
                  URL="https://dl.dropbox.com/u/######/wosm-library-EN.xml";        

        }
         sharedPrefs.getBoolean("french", true);
            {
                  URL="https://dl.dropbox.com/u/######/wosm-library-FR.xml";        
        } 



    ArrayList<HashMap<String, String>> libraryList = new ArrayList<HashMap<String, String>>();

    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(URL); 
    Document doc = parser.getDomElement(xml); 

    NodeList nl = doc.getElementsByTagName(KEY_ITEM);

    for (int i = 0; i < nl.getLength(); i++) {

        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) nl.item(i);

        map.put(KEY_ID, parser.getValue(e, KEY_ID));
        map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
        map.put(KEY_DESCRIPTION, parser.getValue(e, KEY_DESCRIPTION));
        map.put(KEY_FILESIZE, parser.getValue(e, KEY_FILESIZE));
        map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));
        map.put(KEY_DOCUMENT_URL, parser.getValue(e, KEY_DOCUMENT_URL));

        libraryList.add(map);
    }


    list=(ListView)findViewById(R.id.list);         
    adapter=new LazyAdapter(this, libraryList);        
    list.setAdapter(adapter);





    list.setOnItemClickListener(new OnItemClickListener() {

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

            String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
            String description = ((TextView) view.findViewById(R.id.artist)).getText().toString();
            //String thumb_url = ((ImageView)view.findViewById(R.id.list_image)).getImageMatrix().toString();
            //String thumb_url = ((TextView) view.findViewById(R.id.thumburl)).getText().toString();            
            String filesize = ((TextView) view.findViewById(R.id.duration)).getText().toString();
            String thumburl = ((TextView) view.findViewById(R.id.imgurl)).getText().toString();
            String doc_url = ((TextView) view.findViewById(R.id.documenturl)).getText().toString();

            Intent in = new Intent(CustomizedListView.this, org.scouts.library.SingleMenuItem.class);
            in.putExtra(KEY_TITLE, title);
            in.putExtra(KEY_DESCRIPTION, description);
            //in.putExtra(KEY_THUMB_URL, thumb_url);
            in.putExtra(KEY_FILESIZE, filesize);
            in.putExtra(KEY_THUMB_URL, thumburl);
            in.putExtra(KEY_DOCUMENT_URL, doc_url);
            startActivity(in);

        }
    });     
}   
}

i only started getting the nullpointer excepetion after i added the preference variable

  • 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-06T23:58:05+00:00Added an answer on June 6, 2026 at 11:58 pm

    Put the SharedPreferences line into you onCreate() method.

    Also you need to use if(){//do something} else {//do something else}

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    if(sharedPrefs.getBoolean("french", false))
    {
       URL="https://dl.dropbox.com/u/######/wosm-library-EN.xml";        
    }
    else
    {
       URL="https://dl.dropbox.com/u/######/wosm-library-FR.xml";        
    } 
    

    A far better way to do this would be to use a resource string for the Dropbox URL and provide different localizations. Then you would not need this code at all.

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

Sidebar

Related Questions

I want to use DOM4j for parsing xml file in Java. I have this
I am parsing xml file by using libxml2.0, the code is below here. I
I am getting an Error parsing XML file: Unbound prefix when I try to
I'm getting EXC_BAD_ACCESS while parsing XML file in my Xcode4 iPhone app Although I
I am parsing xml file from server using xmlParser in Android. When i print
I've used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I
When parsing an xml file in android, I'm doing like this: try { InputStream
I am parsing a XML file supplied by some software. Part of the parsing
I'm parsing an xml file and i've been trying to strip out the whitespace
I am parsing an xml file. One of the method is below : public

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.