🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12437

Re: Array of JCheckBoxes

#12437
From: Vasudevan Srinivasan
Date: Tue, 29 Dec 1998 00:00
33 lines
1575 bytes
You are right, i realized that as soon as i put the post.
though i didnt initialize, i was blindly thinking it was there !
Thanks anyway.

Jason Burton wrote:

> >JCheckBox chkBoxes[];
> >String names[] = {"A1","A2",...};
> >...
> >chkBoxes = new JCheckBox[10];
> >for (i=0;i<10;i++) {
> >    chkBoxes[i].setText(names[i]);
> >    panel.add(chkBoxes[i]);
> >}
> >
> >And this gives me a null pointer exception at chkBoxes[i].setText(...);
>
> You need to call a JCheckBox constructor.  I'm guessing that you believe
> that the:
> chkBoxes = new JCheckBox[10];
> line created 10 JCheckBoxes for you.  This is not the case.  It simply
> defined the bounds of your array.  You need to create an instance of each
> checkbox.  Example:
>
> chkBoxes = new JCheckBox[10];
> for (i=0;i<10;i++) {
>     chkBoxes[i] = new JCheckBox();
>     chkBoxes[i].setText(names[i]);
>     panel.add(chkBoxes[i]);
> }
>
> Hope this helps,
> Jason Burton
Technical Details
Message-ID: <36894E92.66F69E1D@netrisk.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3689308F.68014E53@netrisk.com> <76be27$pj724@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,67c16edf41741832
X-Google-Attributes: gid111d45,public
From: Vasudevan Srinivasan <vasudevan@netrisk.com>
Subject: Re: Array of JCheckBoxes
Date: 1998/12/29
Message-ID: <36894E92.66F69E1D@netrisk.com>
X-Deja-AN: 426895760
Content-Transfer-Encoding: 7bit
References: <3689308F.68014E53@netrisk.com> <76be27$pj724@forums.borland.com>
To: Jason Burton <jasonb@tmscorp.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing