Adding RosterListener doesn't work properly

Hi all,

I am new to smack API. I am trying to develop a chat application. I am trying to add a RosterListener to the Roster as follows.

Roster roster = connection.getRoster();

roster.addRosterListener(new RosterListener() {
public void entriesAdded(Collection addresses) {}
public void entriesDeleted(Collection addresses) {}
public void entriesUpdated(Collection addresses) {}
public void presenceChanged(Presence presence) {
System.out.println("Presence changed: " + presence.getFrom() + " " + presence);

But I found that when the user changes his presence, it is getting reflected in Openfire server but the **presenceChanged() **method is not getting called.

The code snippet shown below is where I change the presence to Do Not Disturb.

Presence presence = new Presence(Presence.Type.available);



The above code is working fine and after executing this the user’s presence in Openfire server is showing as dnd.

What may be the cause of this error? Please help me to resolve this issue.

Thanks in Advance