JavaDude32
Programmer
I'm implementing a single Linked List in my program to handle the connected Users. My problem is that a NullPointerException is thrown when trying to access a value that is null, I guess it is to be expected, should I try to do the addition code in a catch statement or is there a better way to do a linked list in Java?
btw the equals method threw the same exception
....
//Register user with the connection pool
private synchronized void addUser(String theUserName, Socket b) {
if(list_start == null) {
list_start = new JocusUser(b, theUserName);
} else {
JocusUser theUser;
for(theUser = list_start; theUser != null; theUser = theUser.next()) {
}
theUser.setNext(new JocusUser(b, theUserName));
}
}
....
public class JocusUser {
private Socket s;
private String name;
private JocusUser nextUser;
JocusUser(Socket b, String userName) {
s = b;
name = userName;
nextUser = null;
}
public void setNext(JocusUser nextUser) {
this.nextUser = nextUser;
}
public JocusUser next() {
return nextUser;
}
....
}
btw the equals method threw the same exception
....
//Register user with the connection pool
private synchronized void addUser(String theUserName, Socket b) {
if(list_start == null) {
list_start = new JocusUser(b, theUserName);
} else {
JocusUser theUser;
for(theUser = list_start; theUser != null; theUser = theUser.next()) {
}
theUser.setNext(new JocusUser(b, theUserName));
}
}
....
public class JocusUser {
private Socket s;
private String name;
private JocusUser nextUser;
JocusUser(Socket b, String userName) {
s = b;
name = userName;
nextUser = null;
}
public void setNext(JocusUser nextUser) {
this.nextUser = nextUser;
}
public JocusUser next() {
return nextUser;
}
....
}