0

I need some help with a line of code in a program that I am writing. I feel like it's going to be some stupid mistake but I just can't seem to figure out what it is...

ArrayList<Integer> knockSequence;               //Default knockSequence
ArrayList<ArrayList<Integer>> customSequences;  //used to store custom sequences for client after   first connection
ArrayList<ServerClient> connectedClients;       //List of connected clients
//...
public void giveNewSequence(ArrayList<Integer> newSequence, ServerClient client) //client MUST be in connectedClients in order for this to work
{
    customSequences.get(connectedClients.indexOf(client)) = newSequence;
}

Why won't the line "customSequences.get(......." work? The error I'm getting is saying that it is looking for a variable but a value is being found. Any feedback is appreciated

2
  • In the future, please post the exact error message. Commented Dec 12, 2013 at 18:16
  • Sorry, first post here. Will remember to do that Commented Dec 12, 2013 at 18:19

1 Answer 1

4

Why won't the line "customSequences.get(......." work?

You're trying to assign a value to the result of a method call. That's what doesn't work. You can only use the assignment operator with a variable.

I suspect you want:

customSequences.set(connectedClients.indexOf(client), newSequence);

You should also consider using a single collection with a composite type which contains the knock, custom sequence and connected client, rather than managing three separate collections where the values are related by index (which is what I suspect you've got here). You might want to use a map as well, rather than a list.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the advice EDIT: the code you posted works, thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.