Hi all,

Just starting out with Tomcat v7.0.53, running under Java SE 1.7.0_51 with Mac 
OSX 10.9. I am writing a chat application using websockets. I have a method 
getUserNames() which allows me to list all logged on users via Session 
chatroomUsers:

 static Set<Session> chatroomUsers = Collections.synchronizedSet(new 
HashSet<Session>());

The method is:

       private Set<String> getUserNames() {
            HashSet<String> returnSet = new HashSet<String>();
            Iterator<Session> iterator = chatroomUsers.iterator();
            while (iterator.hasNext()) 
returnSet.add(iterator.next().getUserProperties().get("username").toString());
            return returnSet;
    }

When I compile this under Eclipse, Tomcat reports the following:


May 01, 2014 8:30:34 PM org.apache.tomcat.websocket.pojo.PojoEndpointBase 
onError
SEVERE: No error handling configured for [ChatroomServerEndpoint] and the 
following error occurred
java.lang.NullPointerException
    at ChatroomServerEndpoint.getUserNames(ChatroomServerEndpoint.java:69)
    at ChatroomServerEndpoint.buildJsonUsersData(ChatroomServerEndpoint.java:53)
    at ChatroomServerEndpoint.handleOpen(ChatroomServerEndpoint.java:29)

Now if I uncomment the while loop in getUserNames(), everything works fine, 
just no users are added to the logged on list on the chat. I'm not sure if the 
issue is with org.apache.tomcat.websocket.pojo.PojoEndpointBase (onError), or 
perhaps that fact that given there are no users logged on, my syntax in the 
while loop is causing the NullPointerException?

Any ideas appreciated!


Cheers, Stacy.

Reply via email to