I am just a doing a little project on my own, trying to create a bingo game. I'm wondering why I'm getting a nullpointer when trying to set the text of a JLabel. The only thing the JLabel needs to display is a random number 1-15.
static JLabel[] boardNumbers = new JLabel[25];
static Random r = new Random();
public static void generateBoard() {
for (int i = 0; i < 1; i++) {
if (i < 5) {
int n = r.nextInt(15);
numbersUsed[i] = n;
boardNumbers[i].setText("" + n);
} else if (i >= 5 && i < 10) {
//i numbers
} else if (i >= 10 && i < 15) {
//n numbers
} else if (i >= 15 && i < 20) {
//g numbers
} else {
//o numbers
}
}
}
The line that is giving me a nullpointer is this line boardNumbers[i].setText("" + n);
For the full source code you can view this: https://github.com/charlieSplittstoser/Bingo/blob/master/Bing0/src/Main.java