Click to See Complete Forum and Search --> : Another question regarding arrays of check boxes


sam_ccld
December 20th, 2002, 10:59 AM
I declare an 6 arrays of JCheckBox each has 6 elements
JCheckBox[] pre = new JCheckBox[6];
JCheckBox[] expr = new JCheckBox[6];
JCheckBox[] mot = new JCheckBox[6];
JCheckBox[] res = new JCheckBox[6];
JCheckBox[] dyn = new JCheckBox[6];
JCheckBox[] appr = new JCheckBox[6];
I am tying to use a FOR loop to fill the setText property

for (int i=0 ; i<6 ; i++){
pre[i].setText(""+i);----------<< error pointing to this line
expr[i].setText(""+i);
mot[i].setText(""+i);
res[i].setText(""+i);
dyn[i].setText(""+i);
appr[i].setText(""+i);

}

And I am getting this errors could u please explain to me why this is happennig note that it compiles ok my checkboxes are in a 2nd frame so when i click my button to show the frame where the checkboxes are it shows me this:
Errors
java.lang.NullPointerException
at ccld_final.pnCcld.jbInit(pnCcld.java:109)

dlorde
December 22nd, 2002, 09:18 AM
You've created arrays of JCheckBox references (which are null by default), but you haven't created and assigned the actual JCheckBoxes to them. So you get a null pointer exception because you're trying to set the text of a null JCheckBox reference.