0

I'm getting a NullPointer exception when I try to add an array of JLabels to my panel.

the error happens in the last line of the inner loop

Panel panneauScore;
Panel panneaujouonsAuGolf;
Label [][] arrayscore = new Label [4][9];

for (int c = 0; c<arrayscore.length; c++){
        for (int p = 0; p<arrayscore[c].length; p++){
            score1 = Choisirrandom();
            nombre[c][p] = score1; 
            arrayscore[c][p]= new Label(String.valueOf(nombre[c][p]));
            panneauScore.add(arrayscore[c][p]);
        }
    }
  • The heuristic for NullPointerExceptions is almost always the same: You should critically read your exception's stacktrace to find the line of code at fault, the line that throws the exception, and then inspect that line carefully, find out which variable is null, and then trace back into your code to see why. You will run into these again and again, trust me. – Hovercraft Full Of Eels May 08 '16 at 15:52
  • Looks like panneauScore is null. Where do you ever initialize it? – Hovercraft Full Of Eels May 08 '16 at 15:53

0 Answers0