Roster.getPresence(user) returns null

Hi,

i am new to smack.

I installed Openfire. and i call the smack API from my application. But Roster.getPresence(user) returns null

But I’'m sure the user is online at that time.

Who can tell me why?

It is very urgent…

Please help me

Thanks

Banu

Hi,

I enclosed the code i used for the above

Roster roster = con.getRoster();

for (Iterator i=roster.getEntries(); i.hasNext(); ) {

RosterEntry entry = (RosterEntry)i.next();

Presence presence = roster.getPressence(entry.getUser());

System.out.println(entry + “\t” + presence;

}[/code]

Thanks

Banu

This question has been asked many times before so a simple search of the forum would have yielded you the answer.

The most likely cause why you are seeing the roster entry as being null is down to one of two things

1: You are not subscribed to the users presence. So you don’'t have the right to see when they are online.

2: You are calling

connection.getRoster();

as soon as you connect and login. You have to bear in mind that xmpp works across a network so you might not have got the full information when you first obtain your roster.

You can try two things here, either stick a Thread.sleep(3000) call into your code or add a RosterListener to your roster, the 2nd is better as it will then listen out for changes and notify you if and when your contacts come online

hth

Jon

Hi,

Thanks for the information.

Below is my code

//code

Roster roster = getRoster(HttpSession);

List rosterList = new ArrayList();

Iterator rosterEntries = roster.getEntries();

if(roster != null)

{

System.out.println("The roster count is " + roster.getEntryCount());

if (roster.getEntryCount() > 0)

{

Iterator i=roster.getEntries();

while(i.hasNext())

{

RosterEntry rosterEntry = (RosterEntry)i.next();

if(rosterEntry != null)

{

String rosterUser = rosterEntry.getUser();

System.out.println("Roster Entry User is " + rosterUser);

Presence presence = roster.getPresence(rosterUser);

if(presence != null){

System.out.println("The value of presence is " + presence);

System.out.println("The presence getStatus is " + presence.getStatus());

}

else

{

System.out.println(“Presence is NULL”);

}

}

else

{

System.out.println(“Roster Entry is NULL”);

}

}

} else {

System.out.println(“The roster is EMPTY”);

}

} else {

System.out.println(“Roster is NULL”);

}

//.

output for the above code is

The roster count is 3

Roster Entry User is banu@localhost

Presence is NULL

Roster Entry User is selvi@localhost

Presence is NULL

Roster Entry User is progen@localhost

Presence is NULL

I am not getting the roster from connection.

I dont know what do you mean by subscribing the presence.

I checked that My roster subscription is default to Accept_All.

Also i tried it using Thread.sleep(5000) . it is not giving me the results.

I need it in urgent…Please Help me…

Thanks for your Help.

Thnaks

banu

Hi,

I changed my code with the rosterListener.

But it give the same result as NULL.

Is there anyother settings to do check…

Please HELP ME!!! URGENT

Thjanks

Banu

Your queries are not urgent now are they at least not to me anyhow

What I mean by subscribing to someone presence is.

User = Tom

User = Dick

User = Harry

Tom sends Dick and Harry a presence packet asking to subscribe to their presence. Dick allows the subscription while Harry declines.

Tom can now see when Dick is online but cannot see when Harry is online.

For a more detailed explanation about presence subscriptions you should read the XMPP sepc