1

我的 API QUICKBLOX 有问题,当我输入“MUC”时,我会跳出相当奇怪的错误,我不知道为什么。

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;
// Multi-User Chat, también conocido como
// MUC, es un robusto protocolo de conferencia basado en XMP. 
// Fue desarrollado como un sistema de chat en grupo para extender 
// la funcionalidad de clientes Jabber/XMPP, cuyo protocolo sólo permite 
// establecer conferencias entre 2 personas. Ha sido acogido como propuesta 
// de extensión XEP-0045, y se ha incluido de forma nativa en el programa servidor ejabberd.
private MultiUserChat muc2;

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 
                muc2 = new MultiUserChat(connection, "2387_chat1@muc.chat.quickblox.com");
                // Discover whether user3@host.org supports MUC or not

                // The room service will decide the amount of history to send
                muc2.join(chatLogin);
                muc2.invite(friendLogin, "Welcome!");
                Log.d("friendLogin ->",friendLogin);
                // Set listener for outcoming messages.
                //chatManager.addChatListener(chatManagerListener);
                muc2.addMessageListener(packetListener);
                addListenerToMuc(muc2);
                //chat1@muc.chat.quickblox.com    ---  el meu
                Message message = new Message(friendLogin + "@muc.chat.quickblox.com");
                message.setBody("Join me for a group chat!");
                message.addExtension(new GroupChatInvitation("2387_chat1@muc.chat.quickblox.com"));
                connection.sendPacket(message);

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

/*** muc */
private void addListenerToMuc(MultiUserChat muc){
    if(null != muc){
        muc.addMessageListener(new PacketListener() {

            @Override
            public void processPacket(Packet packet) {
                Log.i("processPacket", "receiving message");
                }
        });
    }
}    

PacketListener packetListener = new PacketListener() {
    @Override
    public void processPacket(Packet packet) {
      Message message = (Message)packet;
      try {
        muc2.sendMessage(message);
    } catch (XMPPException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
      //System.out.println("got message " + message.toXML());
    }
};  


private PacketInterceptor packetInterceptor = new PacketInterceptor() {

    @Override
    public void interceptPacket(Packet packet) {
         System.out.println("Sending message: " + packet.toString());
         Message message = muc2.createMessage();
         message.setBody("Hello from producer, message " +
                " ");
         try {
            muc2.sendMessage(message);
        } catch (XMPPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
};

/***/

错误:

05-20 23:16:19.679: E/AndroidRuntime(3361): FATAL EXCEPTION: Thread-277
05-20 23:16:19.679: E/AndroidRuntime(3361): java.lang.NullPointerException
05-20 23:16:19.679: E/AndroidRuntime(3361):     at org.jivesoftware.smackx.muc.MultiUserChat$1.connectionCreated(MultiUserChat.java:114)
05-20 23:16:19.679: E/AndroidRuntime(3361):     at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:607)
05-20 23:16:19.679: E/AndroidRuntime(3361):     at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:556)
05-20 23:16:19.679: E/AndroidRuntime(3361):     at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:984)
05-20 23:16:19.679: E/AndroidRuntime(3361):     at com.quickblox.sample.chat.MyChatController$5.run(MyChatController.java:73)
05-20 23:16:19.679: E/AndroidRuntime(3361):     at java.lang.Thread.run(Thread.java:856)
05-20 23:16:19.807: E/Trace(3445): error opening trace file: No such file or directory (2)
4

2 回答 2

1

Dropbox 示例: https : //dl.dropboxusercontent.com/u/2239636/java.txt 但抛出 ThreadNullPointerException 或错误 XML。

这是错误 XML:https ://dl.dropboxusercontent.com/u/2239636/errors.txt

如果我使用另一个 android-smack - x 我得到:

05-21 18:16:17.409: E/AndroidRuntime(2352): FATAL EXCEPTION: main
05-21 18:16:17.409: E/AndroidRuntime(2352): java.lang.VerifyError: com/quickblox/sample/chat/MyChatController
05-21 18:16:17.409: E/AndroidRuntime(2352): at com.quickblox.sample.chat.ChatActivity.onCreate(ChatActivity.java:81)

现在有错误:

05-21 23:30:32.075: W/System.err(2579): java.lang.NullPointerException
05-21 23:30:32.075: W/System.err(2579):     at org.jivesoftware.smackx.muc.MultiUserChat$1.connectionCreated(MultiUserChat.java:115)

这是问题所在,但我不知道此代码:

http://www.code.google.com/p/asmack/issues/detail?id=13

解决了。

于 2013-05-21T14:50:17.123 回答
0

看起来您的 Smack 配置未正确初始化。这是一个已知问题,在此处此处进行报告并在此处进行解释。

于 2013-05-20T21:39:06.147 回答