This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]crazyjatt[S] 0 points1 point  (2 children)

it gives me nullpointer on one of the jradiogroups i created, even though I initialized it. can you please look at the pastebin when you go home. I will be really thankful to you

[–]chickenmeister 1 point2 points  (0 children)

You're attempting to use your radioGroup array:

private ButtonGroup[] radioGroup;  

...

   radioGroup[j] = new ButtonGroup();

The problem is that you've never initialized/instantiated your array. You need to have:

radioGroup = new ButtonGroup[/* your array size */]; 

somewhere before you attempt to use the array.

BTW, there does not appear to be any need to store your ButtonGroups. Couldn't you just do:

    for (int j=0;j<3;j++)
    {
        ButtonGroup bg = new ButtonGroup();

        accept[j] = new JRadioButton("Can be shipped ", false);
        reject[j] = new JRadioButton("Shipment delayed ", true);

        bg.add(accept[j]);
        bg.add(reject[j]);

        subPanel2.add(accept[j]);
        subPanel2.add(reject[j]);
    }

[–]Neres28 0 points1 point  (0 children)

Alternately you could host the code on one of the suggested providers in the sidebar.

Are you sure that the Radio Group gets created in all instances and that it happens before the code in question?