android - 更改包名称时出现奇怪的解析问题

标签 android android-xml android-parser

更改我的应用程序的主程序包名称时,我遇到了一个奇怪的 xml 解析问题。更改后一切都出错了,我发现从网络解析的文本就像垃圾数据。我已经检查了我从中解析数据的 RSS 提要,但它工作正常。我的共享偏好不起作用,mysql 数据库也有问题。我附上了屏幕截图(它是一个显示新闻标题的 GridView )。请看一下。我还附上了解析 xml 的代码。任何帮助将不胜感激..提前致谢...

enter image description here

public static void parse() { //method to parse XML feeds

    URL url;

    try {

        url = new URL(urls);

        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) {

            DocumentBuilderFactory dbf = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc;
            doc = db.parse(url.openStream());
            doc.getDocumentElement().normalize();

            NodeList itemLst = doc.getElementsByTagName("item");

            nl = doc.getElementsByTagName(KEY_HEAD);

            Description = new String[itemLst.getLength()];// ........
            Title = new String[itemLst.getLength()];
            Tit = new String[itemLst.getLength()];
            Tit2 = new String[itemLst.getLength()];
            Desc = new String[itemLst.getLength()];
            Desc2 = new String[itemLst.getLength()];
            image = new String[itemLst.getLength()];

            for (int i = 0; i < itemLst.getLength(); i++) {

                Node item = itemLst.item(i);
                if (item.getNodeType() == Node.ELEMENT_NODE) {
                    Element ielem = (Element) item;
                    NodeList title = ielem.getElementsByTagName("title");
                    NodeList date = ielem.getElementsByTagName("pubDate");
                    NodeList description = ielem
                            .getElementsByTagName("description");
                    Tit[i] = title.item(0).getChildNodes().item(0)
                            .getNodeValue();

                    Desc[i] = description.item(0).getChildNodes().item(0)
                            .getNodeValue();



                    Tit2[i] = Translate.title(Tit[i]);
                    Desc2[i] = Translate.description(Desc[i]);






                    if (Headlines.headflag == "malayalam") {
                        Desc2[i] = Desc2[i].replace("read more", "IqSpX�");
                    }
                    Title[i] = Tit2[i];
                    if (Desc2[i].contains("<img ")) {
                        String img = Desc2[i].substring(Desc2[i]
                                .indexOf("<img "));
                        String cleanUp = img.substring(0,
                                img.indexOf(">") + 1);
                        img = img.substring(img.indexOf("src=") + 5);
                        int indexOf = img.indexOf("'");
                        if (indexOf == -1) {
                            indexOf = img.indexOf("\"");
                        }
                        img = img.substring(0, indexOf);

                        // setImgLink(img);
                        if (Headlines.headflag == "malayalam") {
                            String img2 = img.replace("files",
                                    "files/imagecache/android_320");
                            Description[i] = Desc2[i].replace(img, img2);
                            image[i] = img2;
                        }

                        else {
                            String img2 = img.replace("files",
                                    "files/imagecache/android_1_img");
                            Description[i] = Desc2[i].replace(img, "");
                            image[i] = img2;
                        }
                    } else {
                        Description[i] = Desc2[i];
                    }

                }

            }

        }

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DOMException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

最佳答案

尝试在你所有的类中搜索你的旧包名

关于android - 更改包名称时出现奇怪的解析问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17802416/

相关文章:

android - 通过 XML 将选项卡添加到操作栏

Android:从服务器获取数据

android - 使用来自 fragment 中 web 服务的 2 个字符串填充 ListView

android - 获取 espresso 中的某个项目

javascript - 需要在 react 导航中设置默认 Prop

android - 恢复应用内购买的安全问题

android - 在线性布局内对齐线性布局,例如whatsapp更改个人资料图片

android - 导航标题显示/初始化错误

android - android解析xml报空指针异常

android - Android 中的 Json DateTime 解析