This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes why am i getting a null pointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "why am i getting a null pointer exception" Watch "why am i getting a null pointer exception" New topic

why am i getting a null pointer exception

budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103

Hi guys budsy again , getting a problem in this code .I am taking two radio buttons and adding it to a buttongroup . Then i run System.out.println() to see the values but im getting a null pointer exception . I have used a similar code but in that i didn't get any error. Please help
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36563
Apart from the fact that action commands are not object-oriented programming . . . don't know.
Put this series of print statements before that line where the error happens.

Then you find out which line is causing the problem. It is also worthwhile seeing what the getSelection method returns. Also which sort of Button that might apply to. And work out whether that is going to be null for anything here.
Matthew Brown

Joined: Apr 06, 2010
Posts: 4242

I suspect it's as simple as this: you haven't selected a button yet. So getSelection() is probably returning null.
I agree. Here's the link:
subject: why am i getting a null pointer exception
Similar Threads
Accessing JRadioButton from another class
no applet displayed
problems w/ JCheckBox's and TableModel
is JApplet an instance of ActionListner according to this code?