【问题标题】:Smack API throws item-not-found(404) exceptionSmack API 抛出 item-not-found(404) 异常
【发布时间】: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 已初始化。代码中没有提到

标签: java xmpp smack


【解决方案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();
              }
          }
      

      【讨论】:

        猜你喜欢
        • 2012-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-31
        • 2019-08-04
        • 2012-09-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多