搭载Android 4.0冰淇淋三明治分析器错误 [英] Android 4.0 ice cream sandwich Parser Errors

查看:159
本文介绍了搭载Android 4.0冰淇淋三明治分析器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了一个应用程序,它从一个API读取信息。

I have made a application which reads information from an Api.

链接:<一个href=\"http://api.amp.active.com/camping/campground/details?contract$c$c=CO&parkId=50032&api_key=2chxq68efd4azrpygt5hh2qu\" rel=\"nofollow\">http://api.amp.active.com/camping/campground/details?contract$c$c=CO&parkId=50032&api_key=2chxq68efd4azrpygt5hh2qu

以下是我的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);
    }

我收到 list.getLength() 0 (是越来越 1 Android中的透水版本),所以解析器这个条件。对于市容标签I M获得所需的列表大小。

#

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.

推荐答案

我能想到的唯一理由是,detailDescription已经是文档的根所以大概元素是您正在寻找的标记。它没有名称为detailDescription任何孩子这么的getElementsByTagName(detailDescription)返回空列表。因此,改变你的code上半年如下:

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" so getElementsByTagName("detailDescription") returns empty list. So change first half of your code as follows:

    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冰淇淋三明治分析器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆