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 при создании комнаты MUC для группового чата XMPP с помощью aSmack
Однако, когда я добавляю
Context context = getApplicationContext();
SmackAndroid.init(context);
к началу моего метода connect() я получаю эту ошибку:
java.lang.NoClassDefFoundError: org.jivesoftware.smack.SmackAndroid
Но я добавил библиотеку aSmack, содержащую класс SmackAndroid, в свой путь сборки в eclipse. Не уверен, как решить эту проблему, так как класс, кажется, находится в пути сборки во время компиляции, но не найден во время выполнения. Какие-либо предложения? Спасибо!