Smack API抛出item-not-found(404)异常

时间:2016-05-31 18:40:07

标签: java xmpp smack

这是代码

Iterator i = MultiUserChat.getJoinedRooms(connectionManager.getXMPPConnection(), "test123@dulanjaya-pc");
while(i.hasNext()) {
    System.out.println(i.next());
}

3 个答案:

答案 0 :(得分:0)

想通了。 需要将服务作为/ Smack

Iterator i = MultiUserChat.getJoinedRooms(connectionManager.getXMPPConnection(), "test123@dulanjaya-pc/Smack");

答案 1 :(得分:0)

也许此代码段对您有所帮助。

boolean supports = MultiUserChat.isServiceEnabled(connection,"test3@pc2010102716/spark");    
if(supports) {   
                Iterator<String> joinedRooms = MultiUserChat.getJoinedRooms(connection,"test3@pc2010102716/spark");  
                while(joinedRooms.hasNext()) {   
                    System.out.println("test3 has joined Room " + joinedRooms.next());   
                }   
            }

答案 2 :(得分:0)

getJoinedRooms的源代码如下所示,告诉我们该方法的第二个参数需要完全限定的xmpp ID。它显示的ID示例不完整,完整的ID应该包含资源名称,例如/ smack,/ spark和/ android。

 /**
     * Returns an Iterator on the rooms where the requested user has joined. The Iterator will
     * contain Strings where each String represents a room (e.g. room@muc.jabber.org).
     *
     * @param connection the connection to use to perform the service discovery.
     * @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
     * @return an Iterator on the rooms where the requested user has joined.
     */
    public static Iterator<String> getJoinedRooms(Connection connection, String user) {
        try {
            ArrayList<String> answer = new ArrayList<String>();
            // Send the disco packet to the user
            DiscoverItems result =
                ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(user, discoNode);
            // Collect the entityID for each returned item
            for (Iterator<DiscoverItems.Item> items=result.getItems(); items.hasNext();) {
                answer.add(items.next().getEntityID());
            }
            return answer.iterator();
        }
        catch (XMPPException e) {
            e.printStackTrace();
            // Return an iterator on an empty collection
            return new ArrayList<String>().iterator();
        }
    }