am try to create notepad in java...

menu item actionlisteners are not working...except exit...

what is the problem with my code???


and is there any sequence follow... because am try to use jScrollpane the text area will be blocked???

code is..

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JFrame;
import javax.swing.JTextArea; 
import javax.swing.JSeparator;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollBar;
import java.awt.Container;
//import javax.swing.JFlowLayout;
import javax.swing.JScrollPane;

class Notepad extends JFrame implements ActionListener{

JMenu file;
JMenu edit ;
JMenu format ;
JMenu view;
JMenu help;
JMenuBar jb;

JMenuItem New ;
JMenuItem open;
JMenuItem save;
JMenuItem save1;
JMenuItem ps ;
JMenuItem print ;
JMenuItem exit;

JMenuItem undo;
JMenuItem cut;
JMenuItem copy;
JMenuItem paste;
JMenuItem delete;
JMenuItem find;
JMenuItem fnext;
JMenuItem replace;
JMenuItem gto;
JMenuItem sall;
JMenuItem tdate;
JMenuItem wwrap;
JMenuItem fon;
JMenuItem sbar;
JMenuItem vhelp;
JMenuItem anp;
JTextArea ja;
JScrollPane jsp;

Notepad(){
//JFrame jf= new JFrame("Program-Notepad");
//setLayout(new JFlowLayout());
setTitle("Program-Notepad");

setVisible(true);
setSize(1024,768);
Container ct= getContentPane();


//jsb.add(ja);
JMenu file = new JMenu("File");
JMenu edit = new JMenu("Edit");
JMenu format = new JMenu("Format");
JMenu view= new JMenu("View");
JMenu help= new JMenu("Help");
JMenuBar jb= new JMenuBar();


//JMenuItem =new JMenuItem("");

jb.add(file);

jb.add(edit);

jb.add(format);

jb.add(view);

jb.add(help);


setJMenuBar(jb);

JTextArea ja= new JTextArea();
add(ja);
JMenuItem New =new JMenuItem("New");
JMenuItem open =new JMenuItem("Open");
JMenuItem save =new JMenuItem("Save");
JMenuItem save1=new JMenuItem("Save AS");
JMenuItem ps =new JMenuItem("Page Setup");
JMenuItem print =new JMenuItem("Print");
exit=new JMenuItem("Exit");

New.addActionListener(this);
open.addActionListener(this);
save.addActionListener(this);
save1.addActionListener(this);
ps.addActionListener(this);
print.addActionListener(this);
exit.addActionListener(this);


file.add(New);

file.add(open);

file.add(save);

file.add(save1);

file.add(ps);

file.add(print);

file.add(exit);



JMenuItem undo=new JMenuItem("Undo");
JMenuItem cut=new JMenuItem("Cut");
JMenuItem copy=new JMenuItem("Copy");
JMenuItem paste=new JMenuItem("Paste");
JMenuItem delete=new JMenuItem("Delete");
JMenuItem find=new JMenuItem("Find");
JMenuItem fnext=new JMenuItem("Find Next");
JMenuItem replace=new JMenuItem("Replace");
JMenuItem gto=new JMenuItem("Goto");
JMenuItem sall=new JMenuItem("Select All");
JMenuItem tdate=new JMenuItem("Time/Date");
edit.add(cut);
edit.add(copy);
edit.add(paste);
edit.add(delete);
edit.add(find);
edit.add(fnext);
edit.add(find);
edit.add(fnext);
edit.add(replace);
edit.add(gto);
edit.add(sall);
edit.add(tdate);
sall.addActionListener(this);
copy.addActionListener(this);
cut.addActionListener(this);
paste.addActionListener(this);
JMenuItem wwrap=new JMenuItem("Word Wrap");
JMenuItem fon=new JMenuItem("Font..");
format.add(wwrap);
format.add(fon);
JMenuItem sbar=new JMenuItem("Status Bar");
view.add(sbar);
JMenuItem vhelp=new JMenuItem("View Help");
JMenuItem anp=new JMenuItem("About Notepad");
help.add(vhelp);
help.add(anp);




//jsp = new JScrollPane(ja);

//ct.add(jsp);



setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e){

if (e.getSource()==sall){
ja.selectAll();
}


/*
if (e.getSource()==New){

ja.setText(" ");

System.out.println("empty up text field");
}
*/

if (e.getSource()==exit){
System.exit(0);
}

if (e.getSource()==copy){
ja.copy();
}
if (e.getSource()==cut){
ja.cut();
}
if (e.getSource()==paste){
ja.paste();
}




}

//public void actionPerformed(ActionEvent ae )
//	{}






}

public class Test$10{
public static void main(String args[]){
System.out.println("Notepad program");


new Notepad();


}
}

menu item actionlisteners are not working...except exit.

Add a println first thing in the listener method to show when it is called and what the value of the ActionEvent is. Then you'll know which menu items have listeners.
You need to add more code for the menu items you want to work. You have code for a few of the menu items. You need to add some for EACH menu item.

.except exit...

Look at the code where you give the exit variable a value. It is different from ALL the other variables that are just in front of it. If exit works and the ones above it don't work, perhaps you should wonder why and change the others to be like you coded exit.

Add a println first thing in the listener method to show when it is called and what the value of the ActionEvent is. Then you'll know which menu items have listeners.
You need to add more code for the menu items you want to work. You have code for a few of the menu items. You need to add some for EACH menu item.

am coded few of the menu item listeners only..but cut,copy,paste are not working why..is there need to any change...

You define a whole load of menu items on lines 16-48, but in your follwing code instead of using those items you create new local variables (lines 61-66 etc), so whatever you do with those local variables has no effect on the instance variables that defined earlier.
In particular, the items you test for in your ActionPerformed are the instance variables, not the ones you added the listener to.
The one exception is exit where, on line 92 you correctly use the instance variable.

You define a whole load of menu items on lines 16-48, but in your follwing code instead of using those items you create new local variables (lines 61-66 etc), so whatever you do with those local variables has no effect on the instance variables that defined earlier.
In particular, the items you test for in your ActionPerformed are the instance variables, not the ones you added the listener to.
The one exception is exit where, on line 92 you correctly use the instance variable.

ya...its local variable...am corrected.. but it cant work..

code:

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JFrame;
import javax.swing.JTextArea; 
import javax.swing.JSeparator;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollBar;
import java.awt.Container;
//import javax.swing.JFlowLayout;
import javax.swing.JScrollPane;
import java.awt.Color;
import java.awt.Font;
class Notepad extends JFrame implements ActionListener{

JMenu file;
JMenu edit ;
JMenu format ;
JMenu view;
JMenu help;
JMenuBar jb;

JMenuItem New ;
JMenuItem open;
JMenuItem save;
JMenuItem save1;
JMenuItem ps ;
JMenuItem print ;
JMenuItem exit;

JMenuItem undo;
JMenuItem cut;
JMenuItem copy;
JMenuItem paste;
JMenuItem delete;
JMenuItem find;
JMenuItem fnext;
JMenuItem replace;
JMenuItem gto;
JMenuItem sall;
JMenuItem tdate;
JMenuItem wwrap;
JMenuItem fon;
JMenuItem sbar;
JMenuItem vhelp;
JMenuItem anp;
JTextArea ja;
JScrollPane jsp;

Notepad(){
//JFrame jf= new JFrame("Program-Notepad");
//setLayout(new JFlowLayout());
setTitle("Program-Notepad");

setVisible(true);
setSize(1024,768);
Container ct= getContentPane();


//jsb.add(ja);
file = new JMenu("File");
edit = new JMenu("Edit");
format = new JMenu("Format");
view= new JMenu("View");
help= new JMenu("Help");
jb= new JMenuBar();


//JMenuItem =new JMenuItem("");

jb.add(file);

jb.add(edit);

jb.add(format);

jb.add(view);

jb.add(help);


setJMenuBar(jb);

JTextArea ja= new JTextArea();
add(ja);
New =new JMenuItem("New");
open =new JMenuItem("Open");
save =new JMenuItem("Save");
save1=new JMenuItem("Save AS");
ps =new JMenuItem("Page Setup");
print =new JMenuItem("Print");
exit=new JMenuItem("Exit");

New.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

//ja.setText("");
}
});

open.addActionListener(this);
save.addActionListener(this);
save1.addActionListener(this);
ps.addActionListener(this);
print.addActionListener(this);
exit.addActionListener(this);


file.add(New);

file.add(open);

file.add(save);

file.add(save1);

file.add(ps);

file.add(print);

file.add(exit);



undo=new JMenuItem("Undo");
 cut=new JMenuItem("Cut");
copy=new JMenuItem("Copy");
paste=new JMenuItem("Paste");
delete=new JMenuItem("Delete");
find=new JMenuItem("Find");
fnext=new JMenuItem("Find Next");
replace=new JMenuItem("Replace");
gto=new JMenuItem("Goto");
sall=new JMenuItem("Select All");
tdate=new JMenuItem("Time/Date");
edit.add(cut);
edit.add(copy);
edit.add(paste);
edit.add(delete);
edit.add(find);
edit.add(fnext);
edit.add(find);
edit.add(fnext);
edit.add(replace);
edit.add(gto);
edit.add(sall);
edit.add(tdate);
sall.addActionListener(this);
copy.addActionListener(this);
cut.addActionListener(this);
paste.addActionListener(this);
 wwrap=new JMenuItem("Word Wrap");
 fon=new JMenuItem("Font..");
format.add(wwrap);
format.add(fon);
 sbar=new JMenuItem("Status Bar");
view.add(sbar);
 vhelp=new JMenuItem("View Help");
 anp=new JMenuItem("About Notepad");
help.add(vhelp);
help.add(anp);




//jsp = new JScrollPane(ja);

//ct.add(jsp);



setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e){

if (e.getSource()==sall){
ja.selectAll();
}


/*
if (e.getSource()==New){

ja.setText(" ");

System.out.println("empty up text field");
}
*/

if (e.getSource()==exit){
System.exit(0);
}

if (e.getSource()==copy){
ja.copy();
}
if (e.getSource()==cut){
ja.cut();
}
if (e.getSource()==paste){
ja.paste();
}




}

//public void actionPerformed(ActionEvent ae )
//	{}






}

public class Test$10{
public static void main(String args[]){
System.out.println("Notepad program");


new Notepad();


}
}

but in the run time...pressing any menu item get a exception errors

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Notepad.actionPerformed(Test$10.java:205)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Notepad.actionPerformed(Test$10.java:202)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Notepad.actionPerformed(Test$10.java:208)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Notepad.actionPerformed(Test$10.java:208)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Notepad.actionPerformed(Test$10.java:208)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Notepad.actionPerformed(Test$10.java:208)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Notepad.actionPerformed(Test$10.java:208)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

C:\Users\Sathya\test>

Edited 5 Years Ago by sathya88: n/a

Null pointer exception usually means uninitialised variable. If you look at the line in your code where that happened its often obvious which variable wasn't initialised, but if not you can add a print statement to check all the values on that line.

HINT: Now you understand the mistake you made with re-declaring your menu items, you need to go through your code to fix the place or places where you made the same mistake with other swing components

This article has been dead for over six months. Start a new discussion instead.