I am trying to create a room using aSmack muc. I have a connect() method which connects to the xmpp server no problem (below).
public void connect() {
ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST,
PORT, SERVICE);
XMPPConnection connection = new XMPPConnection(connConfig);
try {
connection.connect();
Log.i("XMPPChatDemoActivity",
"Connected to " + connection.getHost());
} catch (XMPPException ex) {
Log.e("XMPPChatDemoActivity",
"Failed to connect to " + connection.getHost());
Log.e("XMPPChatDemoActivity", ex.toString());
setConnection(null);
}
try {
connection.login(USERNAME, PASSWORD);
Log.i("XMPPChatDemoActivity",
"Logged in as " + connection.getUser());
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
setConnection(connection);
} catch (XMPPException ex) {
Log.e("XMPPChatDemoActivity", "Failed to log in as " + USERNAME);
Log.e("XMPPChatDemoActivity", ex.toString());
setConnection(null);
}
}
However when I try to use the .create function in the createRoom method below:
private void createRoom() {
MultiUserChat muc = new MultiUserChat(connection,
"name@conference.<myxmppserver>");
try {
if (connection != null) {
muc.create("testroom");
Form form = muc.getConfigurationForm();
Form submitForm = form.createAnswerForm();
for (Iterator fields = form.getFields(); fields.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType())
&& field.getVariable() != null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer("muc#roomconfig_publicroom", true);
muc.sendConfigurationForm(submitForm);
}
} catch (Exception e) {
e.printStackTrace();
}
}
它给了我一个ClassCastException错误,解决方案就在这里:ClassCastException when creating MUC room for XMPP group chat using aSmack
但是当我添加
时 Context context = getApplicationContext();
SmackAndroid.init(context);
到我的connect()方法的开头,我收到此错误:
java.lang.NoClassDefFoundError:org.jivesoftware.smack.SmackAndroid
但是我在eclipse中添加了包含类SmackAndroid的aSmack库到我的构建路径。不知道如何解决这个问题,因为类似乎在编译时在构建路径中,但在运行时找不到。有什么建议?谢谢!
答案 0 :(得分:1)
回答你的问题:
java.lang.NoClassDefFoundError:org.jivesoftware.smack.SmackAndroid
但是我添加了包含SmackAndroid类的aSmack库 在eclipse中我的构建路径。不知道如何解决这个问题 该类似乎在编译时在构建路径中,但不是 在运行时发现。有什么建议?谢谢!
您是否尝试在属性&gt;下设置asmack库? java build path&gt;订单和出口菜单? (不仅是Libraries选项卡)似乎编译没有那个错误。