Roster Prescence Problem

Dear Sir,

I have written the following code, which works perfectly fine and gives me the buddy/roster list for a particular user on the debugger window. Iam able to see the prescence of persons in the buddy list as they come and go online and offline, as I said on the debugger window. I would like to if there is any I can display the buddy/roster list and their prescence for a particular user on the command prompt.

import org.jivesoftware.smack.*;

import java.util.*;

public class TestLoginadmin {

public static void main(String [] args) throws Exception {

XMPPConnection.DEBUG_ENABLED = true;

String server = “128.*..***”;

XMPPConnection con = new XMPPConnection(server);

final Roster roster = con.getRoster ();

if (con.isConnected())

{

System.out.println (“at -” server"- connected");

con.login(“admin”, “abc123”);

System.out.println (“Roster For Admin is :”);

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

{

System.out.println(i.next());

}

System.out.println (“Connected as Admin to view roster presence”);

}

else

{

System.out.println(“not connected with -“server””);

}

//ADDING a Roster Listener

roster.addRosterListener

(

new RosterListener()

{

public void rosterModified()

{

// Ignore event for this example.

}

public void presenceChanged(String user)

{

// If the presence is unavailable then “null” will be printed,

// which is fine for this example.

System.out.println("Presence changed: " + roster.getPresence(user));

}

}

);

}//end of Main

}// end of TestLogin

This is what I get on the command prompt when i run the program…

at -128.*..***- connected

Roster For Admin is :

Connected as Admin to view roster presence

Presence changed: available: available

Presence changed: null

this is when one of the persons in my buddy list logg’'s in and loggs out . I would like to display the name of the user in my buddy list at the command prompt.

Hoping that some one will help me.

Thanking you

Sincerely

rvenkat

Dear Venkat

I do not see any problem on your code to display the roster for the user. When the code is run it would display the entries on the roster in the format

nickname: name@server

Please check if you have entries on the roster or you could create and add some buddies from a full blown client and then check your code.

Hope this helps.

  • Rajesh

hi

i’'m using the following code to display the buddy list.

final Roster roster = con.getRoster();

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

System.out.println(i.next());

System.out.println("\t"+ roster.getPresence(i));

}

i get the following error

C:\smack\classes>javac exp.java

exp.java:21: getPresence(java.lang.String) in org.jivesoftware.smack.Roster cann

ot be applied to (java.util.Iterator)

System.out.println("\t"+ roster.getPresence(i));

if i remove the roster.getPresence i’'m able to display the list of people present on friend list.

i want to print the name followed by the status of the user.any suggestions ???

Sara

Sara,

I think people are happy to answer questions, but at the same time you need to take responsibility for carefully reviewing your own code before posting. The exception you get explains exactly what the problem is – you can’‘t pass in an Iterator to the getPresence method. Doing so wouldn’'t make any sense anyway. The code you should use:

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;
}

Regards,

Matt

Matt ,I hope i wont repeat the same mistake again.

Sara