I am getting class cast exception while creating muc in android.
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)
You can create user Group by ,
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 you wated to create Group Chat in xmpp try the following method. (** UNCHECKED )
public class createMucAT extends AsyncTask<Void, Void, MultiUserChat> {
private RosterGroup group;
private Connection conn;
private String groupId;
private String groupName;
public createMucAT(Connection conn, RosterGroup group, String groupId,
String groupName) {
this.group = group;
this.conn = conn;
this.groupId = groupId;
this.groupName = groupName;
}
@Override
protected MultiUserChat doInBackground(Void... params) {
String groupTag = group.getName();
MultiUserChat chat = null;
try {
chat = createGroupChat(conn, groupId, groupTag, conn.getUser());
} catch (XMPPException e) {
e.printStackTrace();
}
return chat;
}
@Override
protected void onPostExecute(MultiUserChat result) {
super.onPostExecute(result);
//handle the result here
}
private MultiUserChat createGroupChat(Connection conn, String groupId, String groupName, String nickname) throws XMPPException {
MultiUserChat muc = new MultiUserChat(conn, groupId + "@" + ConnectionService.CONFERENCE_IP_ADDRESS);
muc.create(nickname);
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>();
owners.add(ConnectionService.getConnection().getUser().toString());
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
submitForm.setAnswer("muc#roomconfig_roomdesc", groupName);
muc.sendConfigurationForm(submitForm);
return muc;
}
}