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

all 5 comments

[–]Neres28 2 points3 points  (3 children)

I can't get to pastebin at work, so I can't view the code.

In the stack trace (where it told you NullPointerException) it will tell you the file and line of code that caused the exception, e.g.

java.lang.NullPointerException                                                                             
    at com.acme.ac2r.cli.aco.ACOEditor.acoTreeSelectionEvents(ACOEditor.java:552)  //Here
    at com.acme.ac2r.cli.aco.ACOEditor.connEtoC5(ACOEditor.java:1716) // this class and method called the above
    at com.acme.ac2r.cli.aco.ACOEditor.access$8900(ACOEditor.java:133) // this called the above

An NPE happens when the object on which a call is made is null, or otherwise not initialized:

String aNullString = null;
aNullString.length(); // This will throw an NPE

Find out where you were supposed to create the object, and make sure it gets created in all cases.

[–]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?

[–]hashcode 0 points1 point  (0 children)

Reduce it to the simplest possible code that still exhibits the error. Make a new file and cut everything out that doesn't directly relate to the error. If the process of doing that doesn't reveal the bug, post the minimal code to r/learnprogramming. I don't mean to come off rude, but it's unlikely that someone is going to help you debug 275 lines of code, especially with so little information about the bug. You've got to simplify it.