• Post Reply Bookmark Topic Watch Topic
  • New Topic

Null pointer exception Radiobuttons  RSS feed

 
Harshit R Shah
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


==============


Any ideas where I went wrong ?
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there I see four potential issues

- use Swing JComponent rather than AWT (Choice and Label), don't to mix AWT with Swing

- you forgot to intialize JRadioButton b0,b5,b10,b20;

- main class isn't proper ( something - public static void main(String[] args) { )

- read Oracle tutorial Initial Thread
 
Harshit R Shah
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m Korbel wrote:there I see four potential issues

- use Swing JComponent rather than AWT (Choice and Label), don't to mix AWT with Swing

- you forgot to intialize JRadioButton b0,b5,b10,b20;

- main class isn't proper ( something - public static void main(String[] args) { )

- read Oracle tutorial Initial Thread


Can you tell me how to initialize the buttons.I am in a fix and am totally new to AWT/swing programs
 
Nam Ha Minh
Ranch Hand
Posts: 512
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harshitsss Shah wrote:
Can you tell me how to initialize the buttons.I am in a fix and am totally new to AWT/swing programs

Using JRadionButtons is pretty simple. Here I googled for you:

- From the Java tutorial: How to Use Buttons, Check Boxes, and Radio Buttons

- From the web: JRadioButton basic tutorial and examples

Hope that helps.
 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harshitsss Shah wrote: . . . Can you tell me how to initialize the buttons. . . .
Same way you initialise any other references. Preferably in the constructor.

Don't try to squeeze so many declarations into one line, and leave some spaces. I doubt whether those buttons need to be fields'; they can probaboy be local variables in the constructor/initGUI method.
 
K. Tsang
Bartender
Posts: 3632
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lines 65-99 should be after all those other create statements. You add the buttons to the panel last just before adding the panel to the frame.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!