开发者

kxml is giving a xmlpullparser exception

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.


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.


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

this is not valid xml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜