gpt4 book ai didi

Android 4.0 Ice Cream Sandwich 解析器错误

转载 作者:行者123 更新时间:2023-11-29 22:17:54 26 4
gpt4 key购买 nike

我制作了一个从 Api 读取信息的应用程序。

链接:http://api.amp.active.com/camping/campground/details?contractCode=CO&parkId=50032&api_key=2chxq68efd4azrpygt5hh2qu

以下是我的代码:

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() 作为 0(在以前的 android 版本中获取 1),所以解析器这个条件.对于便利设施标签,我正在获得所需的列表大小。

最佳答案

我能想到的唯一原因是“detailDescription”已经是文档的根,所以 element 可能是您正在寻找的标签。它没有任何名为“detailDescription”的子项,因此 getElementsByTagName("detailDescription") 返回空列表。因此,请按如下方式更改代码的前半部分:

    Log.i("ZealDeveloper","I M In detail   " + element.getTagName()); 
if(element.getTagName().equalsIgnoreCase("detailDescription")) {

description = element.getAttribute("description");
drivingDirection = element.getAttribute("drivingDirection");
latitude = element.getAttribute("latitude");
longitude = element.getAttribute("longitude");
}

/* rest of your code...*/

关于Android 4.0 Ice Cream Sandwich 解析器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8066453/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com