Quick Java LinkedList problem
Basically I'm rather new to Java and I have a problem with understanding a line and getting it to work.
Heres the line of code:
LinkedList<ClientWorkers> clients = SingletonClients.getClients();
Heres the procedure its in:
ClientWorker(Socket client, JTextArea textArea) {
this.client = client;
this.textArea = textArea;
String line = in.readLine();
LinkedList<ClientWorkers> clients = SingletonClients.getClients();
for(int i = 0; i < clients.size(); i++) {
ClientWorker c = clients.get(i);
//The client doesn't need to get it's own data back.
if(c == this){
continue;
}
c.writeString(line);
}
}
The errors it's throwing are:
SocketThrdServer.java:20: cannot find symbol
symbol : class LinkedList
location: class ClientWorker
LinkedList<ClientWorker> clients = SingletonClients.getClients();
^
SocketThrdServer.java:20: cannot find symbol
symbol : variable
SingletonClients location: class ClientWorker
LinkedList<ClientWorker> clients = SingletonClients.getClients();
Does anyone have any idea how I can get it sorted? I'm assuming the LinkedList is being defined wron开发者_如何学运维g and SingletonClients isn't being defined at all but I'm not sure what to define them as in this context?
Thanks in advance!
You need to import java.util.LinkedList;
at the beginning of the java file if you want to use LinkedList without its fully qualified name (i.e. if you want to be able to say "LinkedList" instead of "java.util.LinkedList").
In the line
LinkedList<ClientWorkers> clients = SingletonClients.getClients();
you've written ClientWorkers instead of ClientWorker. This is an error. It should be:
LinkedList<ClientWorker> clients = SingletonClients.getClients();
sounds like a classpath problem, although LinkdList belongs to the java.util package so it is always available. I suggest that you check the import statements at the top of your class file to see if you are using the correct LinkedList class
精彩评论