Hi, I'm having the following error with the below code, and I have no idea how to fix it. Any suggestions would be greatly appreciated.
Exception in thread "main" java.lang.NullPointerException
at Experiment.runExperimentOnce(Experiment.java:29)
at Experiment.runExperimentManyTimes(Experiment.java: 37)
at PT5.main(PT5.java:24)
import java.awt.Color; import java.util.ArrayList; public class Experiment { private Aviary av; private int[] results = new int[11]; public Experiment (Aviary x) { x = av; } public void printResults() { for(int i=0; i<=11; i++){ System.out.println(results[i]); } } public int howManyRed(ArrayList<Bird> x) { int count = 0; for(Bird i : x) { if (i.getMyColor()==Color.red) { count++; } } return count; } public void runExperimentOnce() { results[howManyRed(av.see10Birds())]++; } public void runExperimentManyTimes(int w) { int x = w; int avg = 0; results = new int[11]; for(int i = 0; i<=x; i++) { runExperimentOnce(); avg = avg + results[i]; } System.out.println(1.0 * avg + " red birds out of 10"); for(int i = 0; i<=x; i++) { int maxindex = results[0]; if (results[i]> maxindex){ maxindex = results[i]; } } } }