powered by Jive Software

Troubles with reconnect tries with MultyUserChat

I have function connect() which contains following lines:

if(null != this.connection && this.connection.isConnected()){

this.connection.close();

}

this.connection = new XMPPConnection(host, port);

MultiUserChat.addInvitationListener(this.connection, this.inviteMsgListener);

This function connects to given host and registers invintation listener.

when I call this function for the first time all works fine.

Then I try to call this function again and I get NullPointerException, stacktrace is

java.lang.NullPointerException

at org.jivesoftware.smackx.muc.MultiUserChat$1.connectionEstablished(Unknown Source)

at org.jivesoftware.smack.XMPPConnection.connectionEstablished(Unknown Source)

at org.jivesoftware.smack.XMPPConnection.init(Unknown Source)

at org.jivesoftware.smack.XMPPConnection.(Unknown Source)

at com.etearth.TF.connect(Unknown Source)

When I do not use MultiUserChat.addInvitationListener() all works fine.

Error is in MultyUserChat in ConnectionEstablishedListener.

If I replace

ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace);

with

ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);

if(null == sdm) return;

sdm.addFeature(discoNamespace);

this error does not appear.

And another workaround, without modifying SMACK sources. I just can call any static method for ServiceDiscoveryManager before establishing any connection, and all will work fine:

ServiceDiscoveryManager.getIdentityName(); //all will work with this call

if(null != this.connection && this.connection.isConnected()){

this.connection.close();

}

this.connection = new XMPPConnection(host, port);

MultiUserChat.addInvitationListener(this.connection, this.inviteMsgListener);