我安卓端 使用 smack4.1.4 对message 扩展一个节点 <ext>

黄业滨 发布于 2015/12/25 14:44
阅读 759
收藏 0
public class Ext implements ExtensionElement {
private String orderID;
public String getOrderID() {
return orderID;
}
public void setOrderID(String orderID) {
this.orderID = orderID;
}
@Override
public String getElementName() {
// TODO Auto-generated method stub
return "ext";
}
@Override
public String getNamespace() {
return "ihelper:chat:text";
}
@Override
public String toXML() {
StringBuilder sb = new StringBuilder();
sb.append("<ext");
sb.append("   xmlns=");
sb.append("'ihelper:chat:text'");
sb.append(">");
sb.append("<orderID>");
sb.append(orderID);
sb.append("</orderID>");
sb.append("</ext>");
return sb.toString();
}

}



下面的时候对 扩展节点的解析

public class ExtProvider extends DataPacketProvider.PacketExtensionProvider {
private String orderID;
private String url;
private String type;


public ExtensionElement parseExtension(XmlPullParser parser)
throws Exception {
Ext ext = new Ext();
StringBuffer buffer = new StringBuffer();
boolean done = false;
while (!done) {
int eventType = parser.getEventType();
switch (eventType) {
case XmlPullParser.START_TAG:
String startTag = parser.getName();
switch (startTag) {
case "orderID":
orderID = parser.nextText();
break;
}
   break;
case XmlPullParser.END_TAG:
String endTag = parser.getName();
switch (endTag) {
case "ext":
done = true;
break;
}
break;
}
}
ext.setOrderID(orderID);
return ext;
}
}


当对方给我发来消息的时候 报

12-21 21:59:50.822: W/AbstractXMPPConnection(5312):     java.lang.NumberFormatException: Invalid long: "null"
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at java.lang.Long.invalidLong(Long.java:125)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at java.lang.Long.parseLong(Long.java:342)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at java.lang.Long.parseLong(Long.java:319)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider$PacketExtensionProvider.parse(DataPacketProvider.java:56)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider$PacketExtensionProvider.parse(DataPacketProvider.java:49)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.provider.Provider.parse(Provider.java:35)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.util.PacketParserUtils.parseExtensionElement(PacketParserUtils.java:929)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.util.PacketParserUtils.addExtensionElement(PacketParserUtils.java:1060)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.util.PacketParserUtils.parseMessage(PacketParserUtils.java:287)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.util.PacketParserUtils.parseStanza(PacketParserUtils.java:151)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.AbstractXMPPConnection.parseAndProcessStanza(AbstractXMPPConnection.java:956)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$500(XMPPTCPConnection.java:140)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:989)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:944)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:959)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at java.lang.Thread.run(Thread.java:841)

请问 是不是 我写的扩展节点以及解析不对 

是不是应该继承DataPacketExtension来写扩展节点呢  有使用过smack4.1.4 对message进行扩展的前辈吗 求指教。谢谢



加载中
0
zigzagroad
zigzagroad
异常信息很明显啊,传递了null
返回顶部
顶部