Android XML parse from URL into listview

feribayek

New Member
I'm getting an unexpected token error and null pointer exception on the below activity and cannot find out where the problem could be. I am parsing the below URL which is an XML file containing provisional Golf player details. I had it working when I had less nodes in the file but now I am receiving the token error which causes null pointer. Could anyone have a look please ? It would be much appreciated. \[code\]public class AndroidXMLParsingActivity extends ListActivity { // All static variables static final String URL = "http://dl.dropbox.com/u/90179278/helloworld.xml"; // XML node keys static final String KEY_PLAYER = "player"; // parent node static final String KEY_ID = "id"; static final String KEY_NAME = "playername"; static final String KEY_DOB = "dob"; static final String KEY_WEIGHT = "weight"; static final String KEY_HEIGHT = "height"; static final String KEY_HANDED = "handed"; static final String KEY_COUNTRY = "country"; static final String KEY_BIO = "bio"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>(); XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(URL); // getting XML Document doc = parser.getDomElement(xml); // getting DOM element NodeList nl = doc.getElementsByTagName(KEY_PLAYER); // looping through all item nodes <item> 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_NAME, parser.getValue(e, KEY_NAME)); map.put(KEY_DOB, parser.getValue(e, KEY_DOB)); map.put(KEY_WEIGHT, parser.getValue(e, KEY_WEIGHT)); map.put(KEY_HEIGHT, parser.getValue(e, KEY_HEIGHT)); map.put(KEY_HANDED, parser.getValue(e, KEY_HANDED)); map.put(KEY_COUNTRY, parser.getValue(e, KEY_COUNTRY)); map.put(KEY_BIO, parser.getValue(e, KEY_BIO)); // adding HashList to ArrayList menuItems.add(map); } // Adding menuItems to ListView ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.list_item, new String[] { KEY_NAME, KEY_DOB, KEY_WEIGHT, KEY_HEIGHT, KEY_HANDED, KEY_COUNTRY, KEY_BIO }, new int[] { R.id.name, R.id.dob, R.id.weight, R.id.height, R.id.handed, R.id.country, R.id.bio }); setListAdapter(adapter); // selecting single ListView item ListView lv = getListView(); }}\[/code\]
 
Back
Top