aSmack 多用户房间创建错误

Posted

技术标签:

【中文标题】aSmack 多用户房间创建错误【英文标题】:aSmack multi user room creation error 【发布时间】:2014-07-10 17:54:04 【问题描述】:

我正在使用 ejabberd 作为 xmpp 服务器和 aSmack API 在 android 中创建聊天多用户聊天

我正在使用以下代码

public boolean createGroup(XMPPConnection connection, String groupName) 
        /*
         * if (connection == null) return false; try 
         * connection.getRoster().createGroup(groupName);
         * Log.v("Group created : ", groupName); return true;  catch (Exception
         * e)  e.printStackTrace(); return false; 
         */
        if (getConnection() == null) 
            try 
                connect();
             catch (XMPPException e) 
                // TODO Auto-generated catch block
                e.printStackTrace();
            
        
        //configure(ProviderManager.getInstance());
        SmackAndroid.init(getApplicationContext());
        MultiUserChat muc = new MultiUserChat(getConnection(),
                "chitchat@conference.folksv.com");

        try 
            muc.create("chitchat");
            Form form = muc.getConfigurationForm();
            Form submitForm = form.createAnswerForm();
            for (Iterator<FormField> fields = form.getFields(); fields.hasNext();) 
                FormField field = (FormField) fields.next();
                if (!FormField.TYPE_HIDDEN.equals(field.getType())
                        && field.getVariable() != null) 
                    submitForm.setDefaultAnswer(field.getVariable());
                
            
            List<String> owners = new ArrayList<String>();
            // Log.i(TAG, "list of owners=====" +owners.toString());
            owners.add("akash");
            submitForm.setAnswer("muc#roomconfig_roomowners", owners);
            muc.sendConfigurationForm(submitForm);
         catch (XMPPException e) 
            e.printStackTrace();
        

        return true;
    

    public void configure(ProviderManager pm) 

        // Private Data Storage
        pm.addIQProvider("query", "jabber:iq:private",
                new PrivateDataManager.PrivateDataIQProvider());

        // Time
        try 
            pm.addIQProvider("query", "jabber:iq:time",
                    Class.forName("org.jivesoftware.smackx.packet.Time"));
         catch (ClassNotFoundException e) 
            Log.w("TestClient",
                    "Can't load class for org.jivesoftware.smackx.packet.Time");
        

        // Roster Exchange
        pm.addExtensionProvider("x", "jabber:x:roster",
                new RosterExchangeProvider());

        // Message Events
        pm.addExtensionProvider("x", "jabber:x:event",
                new MessageEventProvider());

        // Chat State
        pm.addExtensionProvider("active",
                "http://jabber.org/protocol/chatstates",
                new ChatStateExtension.Provider());
        pm.addExtensionProvider("composing",
                "http://jabber.org/protocol/chatstates",
                new ChatStateExtension.Provider());
        pm.addExtensionProvider("paused",
                "http://jabber.org/protocol/chatstates",
                new ChatStateExtension.Provider());
        pm.addExtensionProvider("inactive",
                "http://jabber.org/protocol/chatstates",
                new ChatStateExtension.Provider());
        pm.addExtensionProvider("gone",
                "http://jabber.org/protocol/chatstates",
                new ChatStateExtension.Provider());

        // Xhtml
        pm.addExtensionProvider("html", "http://jabber.org/protocol/xhtml-im",
                new XHTMLExtensionProvider());

        // Group Chat Invitations
        pm.addExtensionProvider("x", "jabber:x:conference",
                new GroupChatInvitation.Provider());

        // Service Discovery # Items
        pm.addIQProvider("query", "http://jabber.org/protocol/disco#items",
                new DiscoverItemsProvider());

        // Service Discovery # Info
        pm.addIQProvider("query", "http://jabber.org/protocol/disco#info",
                new DiscoverInfoProvider());

        // Data Forms
        pm.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());

        // MUC User
        pm.addExtensionProvider("x", "http://jabber.org/protocol/muc#user",
                new MUCUserProvider());

        // MUC Admin
        pm.addIQProvider("query", "http://jabber.org/protocol/muc#admin",
                new MUCAdminProvider());

        // MUC Owner
        pm.addIQProvider("query", "http://jabber.org/protocol/muc#owner",
                new MUCOwnerProvider());

        // Delayed Delivery
        pm.addExtensionProvider("x", "jabber:x:delay",
                new DelayInformationProvider());

        // Version
        try 
            pm.addIQProvider("query", "jabber:iq:version",
                    Class.forName("org.jivesoftware.smackx.packet.Version"));
         catch (ClassNotFoundException e) 
            // Not sure what's happening here.
        

        // VCard
        pm.addIQProvider("vCard", "vcard-temp", new VCardProvider());

        // Offline Message Requests
        pm.addIQProvider("offline", "http://jabber.org/protocol/offline",
                new OfflineMessageRequest.Provider());

        // Offline Message Indicator
        pm.addExtensionProvider("offline",
                "http://jabber.org/protocol/offline",
                new OfflineMessageInfo.Provider());

        // Last Activity
        pm.addIQProvider("query", "jabber:iq:last", new LastActivity.Provider());

        // User Search
        pm.addIQProvider("query", "jabber:iq:search", new UserSearch.Provider());

        // SharedGroupsInfo
        pm.addIQProvider("sharedgroup",
                "http://www.jivesoftware.org/protocol/sharedgroup",
                new SharedGroupsInfo.Provider());

        // JEP-33: Extended Stanza Addressing
        pm.addExtensionProvider("addresses",
                "http://jabber.org/protocol/address",
                new MultipleAddressesProvider());

        // FileTransfer
        pm.addIQProvider("si", "http://jabber.org/protocol/si",
                new StreamInitiationProvider());

        pm.addIQProvider("query", "http://jabber.org/protocol/bytestreams",
                new BytestreamsProvider());

        // Privacy
        pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());
        pm.addIQProvider("command", "http://jabber.org/protocol/commands",
                new AdHocCommandDataProvider());
        pm.addExtensionProvider("malformed-action",
                "http://jabber.org/protocol/commands",
                new AdHocCommandDataProvider.MalformedActionError());
        pm.addExtensionProvider("bad-locale",
                "http://jabber.org/protocol/commands",
                new AdHocCommandDataProvider.BadLocaleError());
        pm.addExtensionProvider("bad-payload",
                "http://jabber.org/protocol/commands",
                new AdHocCommandDataProvider.BadPayloadError());
        pm.addExtensionProvider("bad-sessionid",
                "http://jabber.org/protocol/commands",
                new AdHocCommandDataProvider.BadSessionIDError());
        pm.addExtensionProvider("session-expired",
                "http://jabber.org/protocol/commands",
                new AdHocCommandDataProvider.SessionExpiredError());
    

但我收到以下错误

07-10 23:18:07.733:E/AndroidRuntime(707):原因:java.lang.IllegalArgumentException:找不到指定变量的字段。 07-10 23:18:07.733: E/AndroidRuntime(707): at org.jivesoftware.smackx.Form.setAnswer(Form.java:326) 07-10 23:18:07.733: E/AndroidRuntime(707): at com.akash.locationaware.XMPPChatDemoActivity.createGroup(XMPPChatDemoActivity.java:308) 07-10 23:18:07.733: E/AndroidRuntime(707): 在 com.akash.locationaware.MessageActivity.sendMessage(MessageActivity.java:90) 07-10 23:18:07.733: E/AndroidRuntime(707): ... 14 更多

我无法理解我错过了什么以及这条消息的含义。

【问题讨论】:

【参考方案1】:

问题是因为下面这行代码

submitForm.setAnswer("muc#roomconfig_roomowners", owners);

删除它让我的房间创建工作。

【讨论】:

以上是关于aSmack 多用户房间创建错误的主要内容,如果未能解决你的问题,请参考以下文章

具有所有者权限的多用户聊天室加入 android + asmack

如何使用 asmack 在 android 中创建多用户聊天应用程序

Slixmpp - 机器人无法连接到多用户房间

使用 aSmack 为 XMPP 群聊创建 MUC 房间时出现 ClassCastException

asmack 是不是有类似于 smackx 的扩展 jar?

如何使用 aSmack 获取 MultiUserChat 房间的 DiscussionHistory?