Array.length error

Whenever I do the array.length function I get the error "The global variable “length” does not exist.

for (int i = 0; i < walls.length; i++) {
    Wall wall = walls.get(i);
    wall.show();
  }

walls is an array of the Wall class

1 Like

length isn’t a function but a field (class property).

If it is so, why are you invoking method get() over walls? walls.get(i);

Java arrays only have methods inherited from the Object class, and nothing more:
Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Object.html

Probably your walls is an ArrayList instead:

If so, invoke its method size() instead of an array’s field length:
Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collection.html#size()

Or even better, go w/ an “enhanced” for ( : ) {} loop:

1 Like

Thanks a bunch. Great person. Big brain.

You were correct

Probably your walls is an ArrayList instead

Ignore this message i did a mistake

Yup! But your posted example doesn’t do that… :relieved:

1 Like

Yeah i realised just after doing it xD. Thanks tho. Great help.