isEmpty() method giving error in a while block

Asked

Viewed 40 times

-1

Hello.
I am developing a board game and in the method below I want to check if in the matrix of integers x any position has been set or is vasia. Error in line: while.

public void verificarJogada(int posicao) {  

//iteradores para linha e coluna  

    int i=0;
    int j=0;

//entra no primeiro laço incrementando j. Ou seja, numa linha, verifica todas as colunas por espaços não vazio.  
do {

//o segundo laço (o laço a baixo) incrementa j para as 3 posições referentes a coluna do tabuleiro.  
    while ((this.!x[i][j].isEmpty()) && (j<2)) {
j++;
}
}

// incrementa i que se refere a linha e verifica novamente em cada coluna se tem espaços não vazios.  
for (i=0; i<3; i++);

// fecha o método e a classe.           

    }

}
  • Format the code. The error is IndexOutOfBoundsException?

  • The X matrix as you said, it’s an integer matrix, right? So integer doesn’t have the isEmpty method. And since it’s whole, you have to have value

  • @ramaral no. I will post the errors here.

  • @Ilario Junior then I have to declare a matrix like this: public int x[][] = new int[3][3]=0; that’s it?

  • By creating a int array it is filled by default with the value 0. I think the test you want to take would be: (this.x[i][j] != 0) && (j<2)

  • @ramaral maybe this way is a solution. Worth trying.

Show 1 more comment

1 answer

1

Your mistake is here:

 while ((this.!x[i][j].isEmpty()) && (j<2)) {

That one ! after the . is not a valid syntax in java, since after . the name of a field or method should be.

Maybe you wanted this:

 while ((!this.x[i][j].isEmpty()) && (j<2)) {

Browser other questions tagged

You are not signed in. Login or sign up in order to post.