This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Array list

At the point when I run the program, it lets me know that my arralist index is somewhere in the range of 0 and 1 beyond the interball. 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class snake extends Actor {
private head k;
private ArrayList<Rectangle> body;
private Rectangle first;
public Snake() {
body = new ArrayList<>();
k = new Head();
body.add(0, k);
first = new Rectangle((k.width / 2 - 1) * k.dimension, k.height / 2 * k.dimension, k.dimension, k.dimension);
body.add(1, first);
}
public void act() {
for (int i = body.size(); i >= 0; i--) {
body.get(i).moveTo(body.get(i - 1).getCenterX(), body.get(i - 1).getCenterY());
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Can someone Tell what's the error i am doing?

0