Android 4.0 冰淇淋三明治解析器错误
我制作了一个从 Api 读取信息的应用程序。
以下是我的代码:
NodeList list = element.getElementsByTagName("detailDescription");
Log.i("ZealDeveloper","I M In detail "+list.getLength());
if(list != null && list.getLength() > 0){
for(int i = 0; i < list.getLength(); i++){
entry = (Element) list.item(i);
description = entry.getAttribute("description");
drivingDirection = entry.getAttribute("drivingDirection");
latitude=entry.getAttribute("latitude");
longitude=entry.getAttribute("longitude");
}
}
NodeList list1 = element.getElementsByTagName("amenity");
Log.i("ZealDeveloper","I M In 2 "+list1.getLength());
if(list1 != null && list1.getLength() > 0){
for(int i = 0; i < list1.getLength(); i++){
entry = (Element) list1.item(i);
nameAmenity = entry.getAttribute("name");
listAmenity.add(nameAmenity);
}
arrAmenity = listAmenity.toArray(new String[listAmenity.size()]);
StringBuilder builder = new StringBuilder();
for ( int i = 0; i < arrAmenity.length; i++ ){
builder.append(arrAmenity[i]+"\n");
}
txtAmenity.setText(builder);
}
#我正在获取 list.getLength()
as 0
(在以前的 Android 版本中获取 1
) ,所以解析器这个条件。对于便利设施标签,我得到了所需的列表大小。
I have made a application which reads information from an Api.
Following is my code :
NodeList list = element.getElementsByTagName("detailDescription");
Log.i("ZealDeveloper","I M In detail "+list.getLength());
if(list != null && list.getLength() > 0){
for(int i = 0; i < list.getLength(); i++){
entry = (Element) list.item(i);
description = entry.getAttribute("description");
drivingDirection = entry.getAttribute("drivingDirection");
latitude=entry.getAttribute("latitude");
longitude=entry.getAttribute("longitude");
}
}
NodeList list1 = element.getElementsByTagName("amenity");
Log.i("ZealDeveloper","I M In 2 "+list1.getLength());
if(list1 != null && list1.getLength() > 0){
for(int i = 0; i < list1.getLength(); i++){
entry = (Element) list1.item(i);
nameAmenity = entry.getAttribute("name");
listAmenity.add(nameAmenity);
}
arrAmenity = listAmenity.toArray(new String[listAmenity.size()]);
StringBuilder builder = new StringBuilder();
for ( int i = 0; i < arrAmenity.length; i++ ){
builder.append(arrAmenity[i]+"\n");
}
txtAmenity.setText(builder);
}
#
I am Getting list.getLength()
as 0
(was getting 1
in pervious versions of android) , so the parser this condition. For amenity tag i m getting the desired list size.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的唯一原因是“detailDescription”已经是文档的根目录,因此可能
element
是您正在寻找的标签。它没有任何名为“detailDescription”的子项,因此getElementsByTagName("detailDescription")
返回空列表。因此,将代码的前半部分更改如下:The only reason I can think of is that "detailDescription" is already root of the document so probably
element
is the tag you are seeking for. It doesn't have any children with the name "detailDescription" sogetElementsByTagName("detailDescription")
returns empty list. So change first half of your code as follows:我有同样的问题。我从 DOM 切换到 XPath。更多此处
I had the same issue. I switch from DOM to XPath. More here