Solved

Exception during event dispatching

Posted on 2007-11-17
6
432 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 Cremers earned 250 total points
ID: 20304001
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
ID: 20304751
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
ID: 20306512
     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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:zolf
ID: 20306522

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
ID: 20306557

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
ID: 20306561

got it.

thanks mate
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
firstChar challenge 13 110
eclipse formatting 6 73
JUnit 4 @Before and @BeforeClass differences 3 48
Error in @AspectJ Based AOP with Spring 2 1
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

920 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

17 Experts available now in Live!

Get 1:1 Help Now