Solved

Exception during event dispatching

Posted on 2007-11-17
6
430 Views
Last Modified: 2008-02-01
when i run the code i get this error

Exception occurred during event dispatching:
java.lang.NullPointerException
      at src.com.AddNewCustomer$JMenuEmailActionListener.actionPerformed(AddNewCustomer.java:505)
      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.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.Dialog$1.run(Unknown Source)
      at java.awt.Dialog$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.awt.Dialog.show(Unknown Source)
      at src.com.MainForm$1.actionPerformed(MainForm.java:819)
      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.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)
0
Comment
Question by:zolf
  • 4
6 Comments
 
LVL 13

Accepted Solution

by:
Bart_Cr earned 250 total points
Comment Utility
Can you post line 505 here? And a few before?

The exception says that something on the line is not instantiated (still is null), while you're trying to call a method on it.
0
 
LVL 23

Assisted Solution

by:rama_krishna580
rama_krishna580 earned 250 total points
Comment Utility
At line 505 of AddNewCustomer.java; the variable/method call is expecting some value but its null....check this line what you have .....????

R.K
0
 

Author Comment

by:zolf
Comment Utility
     ActionListener JMenuEmailActionListener = new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                  String str = e.getActionCommand();
                  
                  Map<String, String> mapping = new HashMap<String, String>();
                JTextField linkedTextField = textField_Email_1;
                //JMenuItem currentItem;
                String currentItem;

                  if(str.equals("Email 1"))
                  {                  
                        emailLabel_1.setText(str);
                        mapping.put(str, linkedTextField.getText());
                        System.out.println(str+"  ,    "+ linkedTextField.getText());
                    String source =  e.getSource().toString();
                   
                    if (mapping.containsKey(source))
                    {
                        linkedTextField.setText(mapping.get(source));
                        System.out.println("IF");
                    }
                    else
                    {
                        linkedTextField.setText("");
                        System.out.println("ELSE");
                    }

                    currentItem = source;

                  }
                  else if(str.equals("Email 2"))
                  {
                        emailLabel_1.setText(str);
                        mapping.put(str, linkedTextField.getText());
                        System.out.println(str+"  ,    "+ linkedTextField.getText());
                        String source =  e.getSource().toString();

                    if (mapping.containsKey(source))
                    {
                        linkedTextField.setText(mapping.get(source));
                        System.out.println("IF");
                    }
                    else
                    {
                        linkedTextField.setText("");
                        System.out.println("ELSE");
                    }

                    source =  e.getSource().toString();
                  }
                  else if(str.equals("Email 3"))
                  {
                        emailLabel_1.setText(str);
                        mapping.put(str, linkedTextField.getText());
                        System.out.println(str+"  ,    "+ linkedTextField.getText());
                        String source =  e.getSource().toString();

                    if (mapping.containsKey(source))
                    {
                        linkedTextField.setText(mapping.get(source));
                        System.out.println("IF");
                    }
                    else
                    {
                        linkedTextField.setText("");
                        System.out.println("ELSE");
                    }

                    source =  e.getSource().toString();
                  }
            }
      };
      
      class JMenuEmailActionListener implements ActionListener {
          private final Map<JMenuItem, String> mapping = new HashMap<JMenuItem, String>();
          private final JTextField linkedTextField;
          private final JLabel labelForTextField;
          private JMenuItem currentItem;

          public JMenuEmailActionListener(JTextField linkedTextField, JLabel labelForTextField, JMenuItem currentItem) {
              this.linkedTextField = linkedTextField;
              this.labelForTextField = labelForTextField;
              this.currentItem = currentItem;
          }

          public void actionPerformed(ActionEvent e) {        ////////////////  505   / //////////////
              mapping.put(currentItem, linkedTextField.getText());

              JMenuItem source = (JMenuItem) e.getSource();
              labelForTextField.setText(source.getActionCommand());

              if (mapping.containsKey(source)) {
                  linkedTextField.setText(mapping.get(source));
              } else {
                  linkedTextField.setText("");
              }

              currentItem = source;
          }
      }
}
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:zolf
Comment Utility

emailLabel_1 = new JLabel();
            emailLabel_1.setText("Email 1");
            emailLabel_1.setBounds(512, 60, 43, 16);
            generalPane.add(emailLabel_1);
       
            JPopupMenuButton emailOpt = new JPopupMenuButton();
            JPopupMenu popupMenuEmail = new JPopupMenu();
            JMenuItem email_1 = new JMenuItem("Email 1");
            JMenuItem email_2 = new JMenuItem("Email 2");
            JMenuItem  email_3 = new JMenuItem("Email 3");
            
            ////email_1.setActionCommand("Email 1");
            ///email_2.setActionCommand("Email 2");
            ////email_3.setActionCommand("Email 3");
            
            ////email_1.addActionListener(JMenuEmailActionListener);
            ////email_2.addActionListener(JMenuEmailActionListener);
            ////email_3.addActionListener(JMenuEmailActionListener);
            
            //You can create it like this:

              ActionListener listener = new JMenuEmailActionListener(textField_Email_1, emailLabel_1, email_1);

      //and simply add it to the three menu items:

                  email_1.addActionListener(listener);
                  email_2.addActionListener(listener);
                  email_3.addActionListener(listener);
0
 

Author Comment

by:zolf
Comment Utility

when i enter a value in the textfield for the first menu item and then select the second menu item i get this error and i did i system.out.println
public void actionPerformed(ActionEvent e)
          {
                 System.out.println(linkedTextField+ "        " +currentItem.getText());
              mapping.put(currentItem, linkedTextField.getText());

i get this

null        Email 1
0
 

Author Comment

by:zolf
Comment Utility

got it.

thanks mate
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now