2013-02-24, 07:50 PM
When you create objects in Java, they are not immediately initialized. The statement
does not create an 2d array of JLabels. All it does is make a pointer (a variable that stores, or "points to", a certain memory address) to one and point it at nothing. So when you try to use that reference, you get a NullPointerException, because it does not exist. In order to actually create your array, you have to ask the JVM to allocate some memory for it. You do this with the new keyword. To initialize an array of JLabels with size skill x 4, you'd write:
You'd also have to change your array indices to 0-3.
Code:
JLabel[][] SkillLabels;does not create an 2d array of JLabels. All it does is make a pointer (a variable that stores, or "points to", a certain memory address) to one and point it at nothing. So when you try to use that reference, you get a NullPointerException, because it does not exist. In order to actually create your array, you have to ask the JVM to allocate some memory for it. You do this with the new keyword. To initialize an array of JLabels with size skill x 4, you'd write:
Code:
JLabel[][] SkillLabels = new JLabel[skill][4];You'd also have to change your array indices to 0-3.

