Declared:
private Man[] man;
This is the initialization:
Man[] man = new Man[1];
for (int i = 0; i < 1; i++){
man[i] = new Man();
for (int j = 0; j < 3; j++){
man[i].eatThis(table.foods[table.topFood-1]);
table.topFood--;
}
}
Want to print this:
System.out.println(getMan(0));
which goes to:
public Man getMan(int k){
return man[k];
}
but I receive NullPointerException. Why? While:
System.out.println(man[0]);
works just fine.
Exception in thread "main" java.lang.NullPointerException
at ManRunning.getMan(ManRunning.java:80)
at ManRunning.newGame(ManRunning.java:133)
at ManRunning.<init>(ManRunning.java:57)
at RunDevilRun.main(RunDevilRun.java:9)