I'm learning about constructors in java but I stuck in the exercise of college that seemed simple, the proposal is to create a class constructor with an array, and call it in another class to attribulate the values to array:
Builder:
public class Populacao {
public void atualizarPopulacao(int i, int j, int populacao){
if (i>=0 && i<4 && j>=0 && j<5 && populacao > 0)
pop[i][j] = populacao;
}
}
Main class:
import javax.swing.JOptionPane;
public class Administracao {
public static void main(String p[]) {
Populacao pop = new Populacao();
int i,j;
int n;
for (i=0; i<4; i++){
for(j=0; j<5; j++){
n = Integer.parseInt(JOptionPane.showInputDialog("Populacão: " + String.valueOf(i+1) + "\nEstado: " + String.valueOf(j+1)));
pop.atualizarPopulacao(i, j, n);
}
}
}
}
But I get the error:
Exception in thread "main" java.lang.NullPointerException
Can anyone help me to assign the values to the array by calling the constructor?