-2

I get aNullPointerException when I try to run this code:

private static Semaphore[] trackSemas;

for(int i=0;i<9;i++){
            trackSemas[i] = new Semaphore(1,true);
        }

Why doesn't this bit of code get a NullPointerException?

Carlton
  • 2,738
  • 6
  • 31
  • 62

1 Answers1

3

You need to initialize the trackSemas array:

private static Semaphore[] trackSemas = new Semaphore[9];
Salah
  • 8,304
  • 3
  • 24
  • 41