-1

I have 5 files .java: Validador.java, Peca.java, Tabuleiro.java, Rainha.java and Nada.java .

Validador.java:

public class Validador {
    public static void main(String[] args) {
        if(args.length == 0) { // sem argumentos

            Tabuleiro tab = new Tabuleiro("DD--"); 
           Peca peca = tab.peca(0,0); 
            System.out.println(peca.podeIrPara(1,1));


        }else if (args[0].equals("filtro")) { // argumento filtro

        }
    }
}

Peca.java :

public abstract class Peca {
    int linha;
    int coluna;
    Tabuleiro tab;
    boolean isNada;

     Peca(Tabuleiro tab, int linha, int coluna) {
        this.tab = tab;
        this.linha = linha;
        this.coluna = coluna;
    }


    boolean vazia() {
        if(isNada) {
            return true;
        }else {
            return false;
        }
    }

    boolean podeIrPara (int linha, int coluna) { // ver se se pode mover para uma posicao
       System.out.println(tab.tamanho_tabuleiro);

        return true;
    }

}

Tabuleiro.java :

public class Tabuleiro extends Peca {
      char tabuleiro_array[][];
      int tamanho_tabuleiro;

 (it shows an error here) --->   Tabuleiro(String repr){ 
        int tamanho_tabuleiro = (int)Math.sqrt(repr.length());
        this.tamanho_tabuleiro = tamanho_tabuleiro;
        char[][] tabuleiro_array = new char[tamanho_tabuleiro][tamanho_tabuleiro]; //cria um tabuleiro
        int coluna = 0;
        int linha = 0;

        for(int i = 0; i < repr.length(); ++i) {
            char ch = repr.charAt(i);
            if(ch == 'D' || ch == '-') {
                tabuleiro_array[linha][coluna] = ch;
                coluna++;
        }
        if(coluna == tamanho_tabuleiro) {
            coluna = 0;
            linha++;
        }
    }
    this.tabuleiro_array = tabuleiro_array;

  }

Rainha.java

public class Rainha extends Peca {
    Rainha(Tabuleiro tab, int linha, int coluna) {
        super(tab, linha, coluna);
        super.isNada = false;
        super.coluna = coluna;
        super.linha = linha;
        super.tab = tab;

    }
}

Nada.java :

public class Nada extends Peca {
    Nada(Tabuleiro tab, int linha, int coluna) {
        super(tab, linha, coluna);
        super.isNada = true;
        super.coluna = coluna;
        super.linha = linha;
        super.tab = tab;
    }
}

When I try to run the code I get this error:

Implicit super constructor Peca() is undefined. Must explicitly invoke another constructor

        at Tabuleiro.<init>(Tabuleiro.java:5)
        at Validador.main(Validador.java:5)

I am a college student and I really need to deliver this project... Does someone knows how to fix this?

  • 1
    Does [this](https://stackoverflow.com/questions/23395513/implicit-super-constructor-person-is-undefined-must-explicitly-invoke-another#:~:text=5%20Answers&text=If%20a%20constructor%20does%20not,get%20a%20compile%2Dtime%20error.&text=call%20to%20the%20parent%20constructor.) answer help? –  Jun 10 '20 at 01:45
  • Does this answer your question? [implicit super constructor Person() is undefined. Must explicitly invoke another constructor?](https://stackoverflow.com/questions/23395513/implicit-super-constructor-person-is-undefined-must-explicitly-invoke-another) – Ivo Mori Jun 10 '20 at 04:20

1 Answers1

0

In Peca.java, add this constructor:

public abstract class Peca {
    int linha;
    ...
    Peca(){}
    ...
}

This is because a call to Tabuleiro(String repr), from your main class Tabuleiro tab = new Tabuleiro("DD--"); will also explicitly invoke the superclass's(Peca in your case) constructor, and since you did not provide any, Java will insert a call to a no-argument constructor of the superclass, i.e super(); It's as if you are doing:

Tabuleiro(String repr){
    super();

    int tamanho_tabuleiro = (int)Math.sqrt(repr.length());
    ...
}

Since it's not defined, you are getting the compile-time error you are seeing.

jumping_monkey
  • 5,941
  • 2
  • 43
  • 58