kxml 给出 xmlpullparser 异常

发布于 2024-12-01 00:27:59 字数 1770 浏览 1 评论 0原文

我检查了 xmlpullparser 异常,但它给了我其他有关 Android 和 SOUP 的问题。我使用 J2me 和普通的 HTTPrequest 来获取 XML,并使用 kXMl 来解析 xml 文本。下面是我正在处理的代码。上面是更多的解析代码,它们工作得很好。

if (parser.getName().equals("comments")) {

                        event = parser.next();
                        boolean flag = false;
                        if (parser.getName().equals("comment")) {
                            flag = true;
                            System.out.println("Flag is true");
                        }
                        while (flag) {
                            event = parser.next();
                            Questioncomments.addComponent(new Label(parser.nextText()));
                            event = parser.next();
                            System.out.println("Inside the While");
                            if (!parser.getName().equals("comment")) {
                                flag = false;
                                System.out.println("Flag is false");
                            }
                        }
                        Questioncomments.repaint();
                    }

XML 我正在发送这一面 - 很棒的问题@dulitha

错误是 -

org.xmlpull.v1.XmlPullParserException:前提条件:START_TAG (位置:TEXT 很棒的问题...@1:399 java.io.InputStreamReader@f828ed68) 在 org.kxml2.io.KXmlParser.Exception(+47) 在 org.kxml2.io.KXmlParser.nextText(+14) 在 com.petmill.mobile.view.qanda.QuestionCanvas.setData(QuestionCanvas.java:189) 在 com.petmill.mobile.view.qanda.QuestionsList$5$1$1.actionPerformed(QuestionsList.java:119)

在我尝试获取文本的行中出现错误 - parser.nextText()。我怎样才能解析 xml 来获取所需的数据...提前致谢。

I checked SO for the xmlpullparser exception but it's giving me others questions with Android and SOUP. I am using J2me and normal HTTPrequest to get my XML and I am using kXMl to parser the xml text. Below is the code that I am working on. And above it is more parsing code and they work perfectly.

if (parser.getName().equals("comments")) {

                        event = parser.next();
                        boolean flag = false;
                        if (parser.getName().equals("comment")) {
                            flag = true;
                            System.out.println("Flag is true");
                        }
                        while (flag) {
                            event = parser.next();
                            Questioncomments.addComponent(new Label(parser.nextText()));
                            event = parser.next();
                            System.out.println("Inside the While");
                            if (!parser.getName().equals("comment")) {
                                flag = false;
                                System.out.println("Flag is false");
                            }
                        }
                        Questioncomments.repaint();
                    }

XML I am sending this side - <comments><comment>Awesome Question @dulitha<idComment></idComment></comment></comments>

The error is -

org.xmlpull.v1.XmlPullParserException: precondition: START_TAG
(position:TEXT Awesome Question...@1:399 in
java.io.InputStreamReader@f828ed68)
at org.kxml2.io.KXmlParser.exception(+47)
at org.kxml2.io.KXmlParser.nextText(+14)
at
com.petmill.mobile.view.qanda.QuestionCanvas.setData(QuestionCanvas.java:189)
at
com.petmill.mobile.view.qanda.QuestionsList$5$1$1.actionPerformed(QuestionsList.java:119)

The error comes up at the line where I am trying to get the text - parser.nextText(). How can I parse the xml to get the data required... Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

_畞蕅 2024-12-08 00:27:59

当您调用 parser.nextText() 时,您似乎并未参与 START_TAG 事件。请检查您在调用 parser.nextText 时是否参与了 ​​START_TAG 事件()parser.getEventType()。我怀疑您在 标记之间有一些空格,因此您的解析器未达到您预期的效果。

也许您还应该考虑一种更安全的方法来解析此 xml。

It looks like you are not on the START_TAG event when you call parser.nextText(). Check that you are on a START_TAG event when you call parser.nextText() with the parser.getEventType(). I suspect that you have some whitespace between <comments> and <comment> tag and therefore your parser is not at the event that you expect it to be.

Perhaps you should also consider a safer approach for parsing this xml.

潇烟暮雨 2024-12-08 00:27:59
<comments>
          <comment>Awesome Question @dulitha
            <idComment></idComment>
           </comment>
</comments>

这不是有效的 xml

<comments>
          <comment>Awesome Question @dulitha
            <idComment></idComment>
           </comment>
</comments>

this is not valid xml

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文