-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
?– ramaral
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
– Ilario Junior
@ramaral no. I will post the errors here.
– André Nascimento
@Ilario Junior then I have to declare a matrix like this: public int x[][] = new int[3][3]=0; that’s it?
– André Nascimento
By creating a
int
array it is filled by default with the value0
. I think the test you want to take would be:(this.x[i][j] != 0) && (j<2)
– ramaral
@ramaral maybe this way is a solution. Worth trying.
– André Nascimento