I am building a program, which should check initially if the array of type (Class) is null. My class has the get and set method, as well as the with and without default constructors. However, when the program initializes, the values of each cell in my array should be null for the ordered filling of the data.
But it is precisely at this point that where error occurs.
If I put my vetor[i] == null
, the program jumps to the end and does not execute the command.
For the execute command I'm putting vetor[i] != null
, but this way I'm overwriting some data.
How do I solve it?
public void Insere(){
for( int i = 0; i < estacionamento.length;i++){
estacionamento[i] = new Veiculo();
if(estacionamento[i] != null){
estacionamento[i].setPlaca(JOptionPane.showInputDialog("informe a placa do veiculo"));
estacionamento[i].setModelo(JOptionPane.showInputDialog("informe o modelo do veiculo"));
}else{
JOptionPane.showMessageDialog(null, " não ha vagas no estacionamento");
} break;
}
}