File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Groovy Fundamentals video training course this week in the Groovy 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: 42682
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: 4530

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