This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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

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: 43980
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: 4541

I suspect it's as simple as this: you haven't selected a button yet. So getSelection() is probably returning null.
Have you checked out Aspose?
subject: why am i getting a null pointer exception
It's not a secret anymore!