[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Exception during event dispatching

Posted on 2007-11-17
6
Medium Priority
?
450 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 13

Accepted Solution

by:
Bart Cremers earned 1000 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 1000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

650 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