I believe this is the same problem as this question... your variable assignment is reversed.
It should be (although this code is still incorrect - see below):
a = clients.get(clients.size()++);
EDIT: this was already answered by Prabhakaran, but apparently people felt the need to downvote my answer.. I think I did address the original question, but I appreciate that my code sample was still incorrect, so I will try to provide a more complete answer:
First of all, as to the "required variable not found" error, if you google it you will see that other SO question as the first hit. clients.get(clients.size()++)
is not a variable, so you can't assign things to it. I am not sure where a
is declared in your code, but assume that it is a variable and thus my suggestion of reversing the assignment.
Next, for the clients.get(clients.size()++)
line, as others have mentioned or alluded to - VAR++
is equivalent to VAR = VAR + 1
, so again is an assignment operation going on. In this case, clients.size()
is not a variable, so you can not increment it. If you wanted the clients.size() + 1
index, you could have written: a = clients.get(clients.size() + 1)
... but that will throw an ArrayIndexOutOfBoundsException
, because you're trying to access an element of clients
beyond its current size!
That is why Prabhakaran rewrote your method as they did, changing that line to a clients.add(c)
call - as it seemed to fit the original intent of the method.