我在基於XMPP的通信的Android應用程序中使用Smack。我正在嘗試使用PrivacyManager創建一個隱私列表。我已經成功創建了一個PrivacyList,但是當我嘗試訪問該列表時,它返回ClassCastException。下面是代碼:Smack getPrivacyList方法拋出classCastException
PrivacyListManager privacyManager;
privacyManager = PrivacyListManager.getInstanceFor(connection);
PrivacyList privacyList = privacyManager.getPrivacyList("msg_block_list");
調查多一點,我已經發現,在調用getRequest方法發生異常在PrivacyListManager.java類上下面的行:
Privacy privacyAnswer =
(Privacy) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
這裏是調用getRequest方法:
private Privacy getRequest(Privacy requestPrivacy) throws XMPPException {
// The request is a get iq type
requestPrivacy.setType(Privacy.Type.GET);
requestPrivacy.setFrom(this.getUser());
// Filter packets looking for an answer from the server.
PacketFilter responseFilter = new PacketIDFilter(requestPrivacy.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send create & join packet.
connection.sendPacket(requestPrivacy);
// Wait up to a certain number of seconds for a reply.
Privacy privacyAnswer =
(Privacy) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
// Interprete the result and answer the privacy only if it is valid
if (privacyAnswer == null) {
throw new XMPPException("No response from server.");
}
else if (privacyAnswer.getError() != null) {
throw new XMPPException(privacyAnswer.getError());
}
return privacyAnswer;
}
我跟着this教程實現PrivacyList。任何人都可以幫忙
在什麼庫中包含所有這些類('PrivacyListManager,PrivacyList,Privacy,SmackConfiguration')。 android sdk中沒有這樣的類。你自己定義了嗎? – teoREtik 2011-04-04 05:54:44
我已經爲此導入了Smack API。一切工作正常只有PrivacyList導致問題。 – Adnan 2011-04-04 05:56:22
通過什麼類的響應對象被定義? – teoREtik 2011-04-04 05:57:37