powered by Jive Software

Can''t get Presence from Roster object

I just started using the smack library and I’'m having problems retrieving presence information from a roster.

I can setup a packetfilter to collect presence packets after the client is already logged in and it works fine when someone changes their status. But I need find the status of each user on the roster when the client is first starting up.

My roster object is definately populated with JIDs. I can iterate through it and see each one. The problem is that Roster.getPresence(“someuser”) always returns null instead of a presence object. Here’‘s what I’'m trying:

roster = connection.getRoster();

Presence presence = roster.getPresence(“user@localhost”);

if (presence.getType() == Presence.Type.UNAVAILABLE) { …

presence.getType() always throws a null pointer exception.

I ran the debug and can see the contact information coming in a soon as the connection is made but the call to roster.getPresence() doesn’'t seem to generate any traffic at all.

Any idea what I’'m missing here?

Thanks for the help!

Billy,

Smack won’‘t have any presence information until it’‘s sent from the server. This is probably what’'s happening in your case – you simply need to wait a few seconds for the presence information to arrive.

Basically, you should change your logic so that null presence is treated as unavailable. You can then add a presence listener to listen for any new presence packets coming in from the server.

Regards,

Matt

Matt,

You were right.

I created a queue in the presence listener and then told the method that does the initial update to check it first. Wor

Thanks for the quick response.

Hi,

I had similar experience. I finally added reload and it gets the roster on login. Here is how it looks in my code:

roster = connection.getRoster();

roster.reload();

Teddy