我有以下 XML 代码
<?xml version="1.0" encoding="windows-1250"?>
<menu>
<item>
<id>0</id>
<name>Pizzerie u soudu</name>
<street>Havlíčkova 3</street>
<city>779 00 Olomouc</city>
<mobile>777035862</mobile>
<telephone>585223042</telephone>
<openinghours>10-22</openinghours>
</item>
<item>
<id>1</id>
<name>Pepinova pizza</name>
<street>©meralova 10</street>
<city>779 00 Olomouc</city>
<mobile>776102022</mobile>
<telephone>-</telephone>
<openinghours>8-22</openinghours>
</item>
</menu>
我想通过以下代码解析它:
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL);
Document doc = parser.getDomElement(xml);
NodeList nl = doc.getElementsByTagName("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_NAME, parser.getValue(e, KEY_NAME));
map.put(KEY_STREET, parser.getValue(e, KEY_STREET));
map.put(KEY_CITY, parser.getValue(e, KEY_CITY));
map.put(KEY_MOBILE, parser.getValue(e, KEY_MOBILE));
map.put(KEY_TELEPHONE, parser.getValue(e, KEY_TELEPHONE));
map.put(KEY_OPENINGHOURS, parser.getValue(e, KEY_OPENINGHOURS));
menuItems.add(map);
}
但我在网上有问题
NodeList nl = doc.getElementsByTagName("item");
它返回有java.lang.NullPointerException
什么问题?