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

Posted

技术标签:

【中文标题】Smack API 抛出 item-not-found(404) 异常【英文标题】:Smack API throws item-not-found(404) exception 【发布时间】:2016-05-31 18:40:06 【问题描述】:

这里是代码

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

【问题讨论】:

发现问题;该代码不包含main(String[]) 方法。此外,connectionManager 永远不会被初始化,并且它们都不包含在类中。 好吧。 connectionManager 已初始化。代码中没有提到 【参考方案1】:

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

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

【讨论】:

【参考方案2】:

也许这段代码 sn-p 对你有帮助。

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());   
                   
            

【讨论】:

【参考方案3】:

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();
        
    

【讨论】:

以上是关于Smack API 抛出 item-not-found(404) 异常的主要内容,如果未能解决你的问题,请参考以下文章

调用 XMPPTCPConnection.login (Smack-4.1.0) 时抛出 SmackException$NoResponseException

Smack 抛出 java.lang.ClassNotFoundException: org.apache.http.conn.ssl.StrictHostnameVerifier

使用 Smack Api for Android 发送和接收消息

Smack 4.1 所需的最低 Android API 级别是多少?

如何在安卓上使用 Smack

GCM 和 Smack API