XMPPConnection遇到麻烦

时间:2013-12-26 16:50:17

标签: android asmack quickblox

我尝试通过QuickBlox sdk获取与登录用户相关的房间信息。我编辑了聊天示例应用程序并尝试根据此=>获取房间信息http://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions/index.html

MultiUserChat.getRoomInfo,MultiUserChat.getJoinedRooms不起作用!连接成功。NullPointer

中出现Iterator<String> joinedRooms = MultiUserChat.getJoinedRooms(connection, "732374-5996@chat.quickblox.com");异常
public class MyChatController {

// ================= QuickBlox ===== Step 8 =================
// Get QuickBlox chat server domain.
// There will be created connection with chat server below.
public static final String CHAT_SERVER = QBChat.getChatServerDomain();

private XMPPConnection connection;

private ConnectionConfiguration config;
private Chat chat;

private String chatLogin;
private String password;
private String friendLogin;

private ChatManager chatManager;

public MyChatController(String chatLogin, String password) {
    this.chatLogin = chatLogin;
    this.password = password;
}

public void startChat(String buddyLogin) {
    this.friendLogin = buddyLogin;

    new Thread(new Runnable() {
        @Override
        public void run() {
            // Chat action 1 -- create connection.
            Connection.DEBUG_ENABLED = true;
            config = new ConnectionConfiguration(CHAT_SERVER);
            connection = new XMPPConnection(config);

            try {
                connection.connect();
                connection.login(chatLogin, password);

                // Chat action 2 -- create chat manager.
                chatManager = connection.getChatManager();

                // Chat action 3 -- create chat.
                chat = chatManager.createChat(friendLogin, messageListener);

                // Set listener for outcoming messages.
                chatManager.addChatListener(chatManagerListener);

             // Muc 2 
                if(connection != null){
                    //  Get the rooms where user3@host.org has joined
                    Log.i("User Login =>", chatLogin);

                    Iterator<String> joinedRooms = MultiUserChat.getJoinedRooms(connection, "732374-5996@chat.quickblox.com");


                    /*while (joinedRooms.hasNext()) {
                        Log.i("Rooms =>", (String) joinedRooms.next());
                    }*/
                }


            } catch (XMPPException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

Logcat =&gt;

 12-27 00:38:23.259: E/AndroidRuntime(15395): FATAL EXCEPTION: Thread-3743
 12-27 00:38:23.259: E/AndroidRuntime(15395): java.lang.NullPointerException
 12-27 00:38:23.259: E/AndroidRuntime(15395):   at      org.jivesoftware.smackx.muc.MultiUserChat.getRoomInfo(MultiUserChat.java:237)
12-27 00:38:23.259: E/AndroidRuntime(15395):    at  com.quickblox.sample.chat.MyChatController$3.run(MyChatController.java:95)
  12-27 00:38:23.259: E/AndroidRuntime(15395):  at java.lang.Thread.run(Thread.java:856)

2 个答案:

答案 0 :(得分:1)

New SDK and chat sample已经发布了一些改进措施。

答案 1 :(得分:0)

我们差不多完成了新的sdk。我们为xmpp聊天添加了新功能,增加了稳定性。样品即将发布。您可以尝试将它用于您的项目。