This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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
Author

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
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
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
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

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