CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2002
    Location
    France
    Posts
    70

    Lightbulb Another question regarding arrays of check boxes

    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
    Code:
      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)
    Last edited by sam_ccld; December 20th, 2002 at 12:05 PM.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    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.
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured