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();
}
}
it gives me a ClassCastException error, for which a solution is here: ClassCastException when creating MUC room for XMPP group chat using aSmack
However when I add the
Context context = getApplicationContext();
SmackAndroid.init(context);
to the beginning of my connect() method, I am getting this error:
java.lang.NoClassDefFoundError: org.jivesoftware.smack.SmackAndroid
But I have added the aSmack library containing the class SmackAndroid to my build path in eclipse. Not sure how to solve this problem since the class seems to be in the build path at compile time, but isn't found at runtime. Any suggestions? Thank you!