I'm trying to put null values on some values of this array:
public ElectricInstallation(){
this.dim1 = (int) Math.random()*85 + 1;
this.dim2 = (int) Math.random()*85 + 1;
this.dim3 = (int) Math.random()*85 + 1;
for(int i = 0; i < this.dim1; i++){
for(int j = 0; j < this.dim2; j++){
for(int k = 0; k < this.dim3; k++){
this.machine[i][j][k] = null;
}
}
}
}
Ergo, I'm trying to create empty values on this array to do this after that:
public void makeScenario(){
for(int i = 0; i < this.dim1; i++){
for(int j = 0; j < this.dim2; j++){
for(int k = 0; k < this.dim3; k++){
if(Math.random() < 0.7){
this.machines[i][j][k] = new ElectricMachine((int) Math.random()*15000 + 1);
if(Math.random() < 0.5){
this.machine[i][j][k].clic();
}
}
}
}
}
}
In other words, I want to make some values to be ElectricMachine and others to be null, but java throws me this: "java.lang.NullPointerException".
What can I do?