XmlPullParserException: unterminated entity ref
只要一执行next方法就报这个异常;
evtType = xmlParser.getEventType();
// 一直循环,直到文档结束
while (evtType != XmlPullParser.END_DOCUMENT) {
switch (evtType) {
case XmlPullParser.START_DOCUMENT:
shoppings = new ArrayList<Shopping>();
break;
case XmlPullParser.START_TAG:
String tag = xmlParser.getName();
// 如果是shopping标签开始,则说明需要实例化对象了
if (tag.equals("shopping")) {
shopping = new Shopping();
} else if (tag.equals("shoppingName")) {
evtType = xmlParser.next();
shopping.setShoppingName(xmlParser.getText());
} else if (tag.equals("shoppingIntegral")) {
evtType = xmlParser.next();
shopping.setShoppingIntegral(xmlParser.getText());
} else if (tag.equals("shoppingPrice")) {
evtType = xmlParser.next();
shopping.setShoppingPrice(xmlParser.getText());
} else if (tag.equals("shoppingNumber")) {
evtType = xmlParser.next();
shopping.setShoppingNumber(xmlParser.getText());
} else if (tag.equals("shoppingSort")) {
evtType = xmlParser.next();
shopping.setShoppingSort(xmlParser.getText());
} else if (tag.equals("shoppingBrand")) {
evtType = xmlParser.next();
shopping.setShoppingBrand(xmlParser.getText());
} else if (tag.equals("shoppingColor")) {
evtType = xmlParser.next();
shopping.setShoppingBrand(xmlParser.getText());
} else if (tag.equals("shoppingGift")) {
evtType = xmlParser.next();
shopping.setShoppingGift(xmlParser.getText());
} else if (tag.equals("shoppingFactory")) {
evtType = xmlParser.next();
shopping.setShoppingFactory(xmlParser.getText());
} else if (tag.equals("shoppingInformation")) {
evtType = xmlParser.next();
shopping.setShoppingInformation(xmlParser.getText());
} else if (tag.equals("shoppingPhoto")) {
evtType = xmlParser.next();
shoppingPhoto = new ArrayList<Integer>();
} else if (tag.equals("item")) {
evtType = xmlParser.next();
shoppingPhoto.add(Integer.parseInt(xmlParser.getText()));
}
break; case XmlPullParser.END_TAG:
// 如果遇到shopping标签结束,则把shopping对象添加进集合中 if (xmlParser.getName().equals("shopping")) {
shopping.setShoppingPhoto(shoppingPhoto);
shoppings.add(shopping);
shopping = null;
shoppingPhoto = null;
}
break;
}
// 如果xml没有结束,则导航到下一个节点
evtType = xmlParser.next();
}
在第一个次进入执行完,开始文档的case后执行最下面的next方法就报异常了
<shoppings>
<shopping>
<shoppingName>双立七件套</shoppingName>
<shoppingIntegral>502</shoppingIntegral>
<shoppingPrice>200</shoppingPrice>
<shoppingNumber>23232323232</shoppingNumber>
<shoppingSort>生活用品</shoppingSort>
<shoppingBrand>双立</shoppingBrand>
<shoppingColor>灰色</shoppingColor>
<shoppingGift>无</shoppingGift>
<shoppingFactory>双立有限公司</shoppingFactory>
<shoppingInformation>中片刀 多用刀 蔬菜刀 水果刀 剔骨刀</shoppingInformation>
<shoppingPhoto>
<item>R.drawable.ic_launcher</item>
<item>R.drawable.ic_launcher</item>
<item>R.drawable.ic_launcher</item>
<item>R.drawable.ic_launcher</item>
<item>R.drawable.ic_launcher</item>
</shoppingPhoto>
</shopping>
</shoppings>
上面是xml格式xmlpull解析