Multiuserchat getOccupants

does anyone have a moment to post some working code snippet successfully calling multiuserchat and retrieving an iterator of occupants with getOccupants() method. Sounds simple enough except that even after creating a muc object and joining either a new or created room successfully (isJoined returns true) - i cannot seem to get a populated list of occupants. I am hoping to try and retrieve a list of fully qualified jabber ids for ‘‘occupants’’ in the room so i can retrieve their resource type. However, the smack javadocs don’‘t seem to suggest this is what i’‘d get. If anyone’'s worked on this and has some ideas be grateful to hear them. Finally, would it be true to say that occupant is the same concept as participant (in GroupChat terminology)? TIA

ok - to add a bit of context - here is an (incomplete so assume everything else is already set up like the connection etc) extract of code. I do not get a list of occupants even though I have logged in on IM clients and entered teh room and chatted between occupants. Any help appreciated:-

ArrayList rooms = (ArrayList) MultiUserChat.getHostedRooms(



for (int i = 0; i < rooms.size(); i++) {

String JId = ((HostedRoom) rooms.get(i)).getJid();

String roomNme = ((HostedRoom) rooms.get(i)).getName();

System.out.println("Room jid: " + JId);

System.out.println("Room name: " + roomNme);

MultiUserChat aMuc = new MultiUserChat(con, roomNme);

if(roomNme.equalsIgnoreCase(myRoomName)) {


boolean isJo = aMuc.isJoined();

System.out.println("Am I joinedd: " + isJo);

if(isJo) {

aMuc.sendMessage(“Hi, Testing the group chat feature!!!”);


if(aMuc.getOccupantsCount() > 0) {

Iterator it = aMuc.getOccupants();

while (it.hasNext()) {

String user = (String);

System.out.println("user : " + user);





Its most likely a timing issue. You try and grab the Occupants as soon as you have joined the room, but the server may take a moment to send them down to you.

You can test for this by adding a simple


After you join the room.

Once in the room, just add a occupant listener, this will allow you to then see whose in the room



I was never successful at using that method.

See some of my many old posts!

I found this method , I believe it was gaston that posted it.

public String getRoomOccupants(XMPPConnection conn, String roomName)throws XMPPException


StringBuffer sb = new StringBuffer();

ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(conn);

DiscoverItems items = discoManager.discoverItems(roomName+CONFERENCE_SERVICE_NAME);

for (Iterator it = items.getItems(); it.hasNext():wink:




DiscoverItems.Item item = (DiscoverItems.Item);

String occupant = parseEntityID(item.getEntityID());

if(sb.length() < 1)




return sb.toString();