kxml 给出 xmlpullparser 异常
我检查了 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 我正在发送这一面 -
错误是 -
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您调用
parser.nextText() 时,您似乎并未参与
请检查您在调用START_TAG
事件。parser.nextText 时是否参与了 START_TAG 事件()
与parser.getEventType()
。我怀疑您在
和
标记之间有一些空格,因此您的解析器未达到您预期的效果。也许您还应该考虑一种更安全的方法来解析此 xml。
It looks like you are not on the
START_TAG
event when you callparser.nextText().
Check that you are on a START_TAG event when you callparser.nextText()
with theparser.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.
这不是有效的 xml
this is not valid xml