-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?

CJR
  • 3,174
  • 6
  • 34
  • 78

1 Answers1

3

You need to initialize the trackSemas array:

private static Semaphore[] trackSemas = new Semaphore[9];
Salah
  • 8,567
  • 3
  • 26
  • 43