本文介绍了如何aSmack XMPP创建集团在android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到类转换异常,而在Android的创造睦。
E / AndroidRuntime(31002):java.lang.ClassCastException:产生的原因:
org.jivesoftware.smack.packet.DefaultPacketExtension
E / AndroidRuntime(31002):在
org.jivesoftware.smackx.muc.MultiUserChat.getMUCUserExtension(MultiUserChat.java:2000)
E / AndroidRuntime(31002):在
org.jivesoftware.smackx.muc.MultiUserChat.create(MultiUserChat.java:364)
解决方案
您可以创建用户组按
公共布尔createGroup(XMPPConnection连接,弦乐组名){
如果(连接== NULL)
返回false;
尝试{
。connection.getRoster()createGroup(组名);
Log.v(创建组,组名);
返回true;
}赶上(例外五){
e.printStackTrace();
返回false;
}
}
如果您wated创建群聊在XMPP试试下面的方法。 (**未选中)
公共类createMucAT扩展的AsyncTask<太虚,太虚,MultiUserChat> { 私人RosterGroup组;
专用连接康恩;
私人字符串的groupId;
私人字符串的groupName;
公共createMucAT(康涅狄格州连接,RosterGroup组,弦乐的groupId,
串组名){
this.group =组;
this.conn =康恩;
this.groupId =的groupId;
this.groupName =组名;
} @覆盖
保护MultiUserChat doInBackground(虚空...... PARAMS){
串groupTag = group.getName();
MultiUserChat聊天= NULL;
尝试{
聊天= createGroupChat(康涅狄格州的groupId,groupTag,conn.getUser());
}赶上(XMPPException E){
e.printStackTrace();
}
返回聊天;
} @覆盖
保护无效onPostExecute(MultiUserChat结果){
super.onPostExecute(结果);
//这里处理结果
} 私人MultiUserChat createGroupChat(康涅狄格州的连接,字符串的groupId,弦乐组名,字符串昵称)抛出XMPPException {
MultiUserChat睦=新MultiUserChat(康涅狄格州的groupId +@+ ConnectionService.CONFERENCE_IP_ADDRESS);
muc.create(昵称);
表格形式= muc.getConfigurationForm();
形成submitForm = form.createAnswerForm();
对于(迭代器< FormField>域= form.getFields(); fields.hasNext();){
FormField字段=(FormField)fields.next();
如果(FormField.TYPE_HIDDEN.equals(field.getType())及!&放大器; field.getVariable()!= NULL){
submitForm.setDefaultAnswer(field.getVariable());
}
}
清单<串GT;业主=新的ArrayList<串GT;();
owners.add(。ConnectionService.getConnection()的getUser()的toString());
submitForm.setAnswer(睦#roomconfig_roomowners,业主);
submitForm.setAnswer(睦#roomconfig_persistentroom,真正的);
submitForm.setAnswer(睦#roomconfig_roomdesc,组名);
muc.sendConfigurationForm(submitForm);
返回睦;
}
}
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;
}
}
这篇关于如何aSmack XMPP创建集团在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!