Hi,
I'm running into a NullPointerException that I can't seem to remedy when attempting to incorporate chat state. I've tracked the source of the exception, but I can't figure out why it's happening. I've stripped out code that I don't think is relevant. The offending code is here:
publicclass SimpleXMPP implements ChatStateListener { Connection connection; ChatStateManager csm; privatevoid connect(){ try{ this.connection = new XMPPConnection("mydomain.tld"); this.connection.connect(); csm = ChatStateManager.getInstance(this.connection); }catch (XMPPException ex) { // handle exception } } publicvoid processMessage(Chat chat, Message msg) { // handle incoming message } publicvoid stateChanged(Chat chat, ChatState state) { // handle state change } }
Logging in and initializing chat happen after connect(), but the problem is at ChatStateManager.getInstance(this.connection). This, in turn, calls:
WeakReference<ChatStateManager> ref = managers.get(connection);
... which returns ref = null.
So, it goes onto:
if (ref == null) { manager = new ChatStateManager(connection); manager.init(); managers.put(connection, new WeakReference<ChatStateManager>(manager)); }
... and the problem is specifically on manager.init(), which looks like this:
privatevoid init() { connection.getChatManager().addOutgoingMessageInterceptor(outgoingInterceptor, filter); connection.getChatManager().addChatListener(incomingInterceptor); ServiceDiscoveryManager.getInstanceFor(connection).addFeature("http://jabber.org/protocol/chatstates"); }
The problem is that ServiceDiscoveryManager.getInstanceFor(connection) returns null. So, we get a NullPointerException on that last line, of course. So you don't have to look it up, getInstanceFor() looks like this:
publicstatic ServiceDiscoveryManager getInstanceFor(Connection connection) { return instances.get(connection); }
instances is empty at this point.
I'm betting that I am simply missing some important step before calling ChatStateManager.getInstance(). Any help would be greatly appreciated. Incidentally, when I remove that line (csm=ChatStateManager.getInstance...) everything works perfectly, except that, obviously, I don't get chat state functionality.
I'm using Smack 3.3.1.
Thank you for looking.
Cheers,
Breandan