I’m getting a compiler error at line 80:
Error: /Users…/AsciiDisplay.java:80: cannot find symbol
Symbol: method draw(AsciiDisplay)
Location: class java.lang.Object
public class AsciiDisplay {
private char [][] grid;
private ArrayList shapes;
public AsciiDisplay() {
grid = new char [30][15];
shapes = new ArrayList();
}
public void updateGrid() {
for(int i = 0; i < shapes.size(); i++) {
shapes.get(i).draw(this); //Line 80: The error is in this line of code.
}
}
}
public class Shape {
protected String id;
protected Coordinate location;
public Shape(String id, Coordinate location) {
this.id = id;
this.location = location;
}
public void draw(AsciiDisplay dis) {
dis.putCharAt(location.getX(),location.getY(),'?');
}
}
What you want is ArrayList of shapes so you need to declare your
ArrayListthat way.Now compiler will know that it only contains Shapes so it will allow you to call methods on shapes on elements of list.
You can have a look at Generics Tutorial for more info.