Must explicitly invoke another constructor

后端 未结 6 1050
借酒劲吻你
借酒劲吻你 2021-01-25 03:27

Why is Eclipse keeps giving me error on the constructor:

 public DenseBoard(Tile t[][]){
      Board myBoard = new DenseBoard(t.length, t[0].length);
  }
         


        
6条回答
  •  北海茫月
    2021-01-25 03:59

    Your constructor needs to call the constructor of the superclass. If the superclass had defined a no-argument constructor, you would not be seeing this error. To expand on the other answers with some code, what you need is

     public DenseBoard(Tile t[][]){
          //You need a way to figure meaningful values to the superconstructor here
          super(intVar1, intVar2);
          Board myBoard = new DenseBoard(t.length, t[0].length); //I think 
         //this now becomes unnecessary?
      }
    

    Or alternatively modify your Board class to include

    public Board()
    {
    ...
    }
    

提交回复
热议问题