java.lang.NullPointerException with JMenu and JMenuBar -
i have jmenubar has 1 menu , 3 jradiobuttonmenuitems
:
jmenubar menubar; jmenu menu = new jmenu("menu"); jradiobuttonmenuitem rbmenuitem;
i declare it:
menu = new jmenu("a menu"); buttongroup group = new buttongroup(); rbmenuitem = new jradiobuttonmenuitem("a radio button menu item"); rbmenuitem.setselected(true); group.add(rbmenuitem); menu.add(rbmenuitem); menubar.add(menu);
and set menu bar:
this.setjmenubar(menubar);
i run file , gives me:
exception in thread "main" java.lang.nullpointerexception @ geometry.tools.main.rectangleframe.<init>(rectangleframe.java:47) @ geometry.tools.main.rectangleframe.main(rectangleframe.java:95) java result: 1
line 47 is:
menubar.add(menu);
and line 95 is:
rectangleframe thr = new rectangleframe();
in the:
public static void main(string[] args){ rectangleframe thr = new rectangleframe(); }
i don't understand why. haven't specified value null
don't see why error.
thanks lot.
menubar
not initialized
jmenubar menubar = new jmenubar();
Comments
Post a Comment