Java 找不到符号:方法绘制(AsciiDisplay)

Java 找不到符号:方法绘制(AsciiDisplay),java,methods,arraylist,compiler-errors,Java,Methods,Arraylist,Compiler Errors,我在第80行遇到编译器错误: 错误:/Users…/AsciiDisplay.java:80:找不到符号 符号:方法DrawAscidSplay 位置:类java.lang.Object public class AsciiDisplay { private char [][] grid; private ArrayList shapes; public AsciiDisplay() { grid = new char [30][15]; shapes = new

我在第80行遇到编译器错误:

错误:/Users…/AsciiDisplay.java:80:找不到符号

符号:方法DrawAscidSplay

位置:类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(),'?');
  }
}

您需要的是形状的ArrayList,因此需要以这种方式声明ArrayList

ArrayList<Shape> shapes;
现在,编译器将知道它只包含形状,所以它将允许您对列表元素上的形状调用方法

您可以查看更多信息