ClassCastException when creating MUC room for XMPP group chat using aSmack

梦想的初衷 提交于 2019-12-01 07:21:27

问题


I am using aSmack for creating chat application. When i am creating groupchat by using this aSmack it gives error. this is the code am using for creating GroupChat.

MultiUserChat muc = new MultiUserChat(connection, "xyz@abc.com");           

try {
    muc.create(u_name);              
    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(PmUser_name);
    submitForm.setAnswer("muc#roomconfig_roomowners", owners);               
    muc.sendConfigurationForm(submitForm);
} catch (XMPPException e) {          
    e.printStackTrace();
}

This is the jar i am using for aSmack asmack-2010.05.07.jar. it supports facebook xmpp, Gtalk xmpp and my own server xmpp chat. Now i want to create group chat for my own server, but it give this error.

E/AndroidRuntime(31002): Caused by: java.lang.ClassCastException:   
org.jivesoftware.smack.packet.DefaultPacketExtension
E/AndroidRuntime(31002):    at  
org.jivesoftware.smackx.muc.MultiUserChat.getMUCUserExtension(MultiUserChat.java:2000)
E/AndroidRuntime(31002):    at    
org.jivesoftware.smackx.muc.MultiUserChat.create(MultiUserChat.java:364)

I have search a lot but still didn't get any idea about how to solve this.

Any help would be appreciated before I pull my hair out.


回答1:


The Packet Providers of Smack where not registered. You get a ClassCastException because Smack is unable to create the correct Packet class instance for MUC. I suggest that you use a newer version of aSmack and follow the instructions in the README, which should initialize and register the Providers for you.



来源:https://stackoverflow.com/questions/15763001/classcastexception-when-creating-muc-room-for-xmpp-group-chat-using-asmack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!