0

i built a code in Frame class and call another class frame named search which contains bottun.
and i try to add this button action :

           s=new Search();
           s.button_1.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent arg) {

            String a =s.text_1.getText();
            JOptionPane.showMessageDialog(new JFrame() ,a);...

I try to run this but it says

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException..
DANA
  • 1
  • 2
  • 3
    See [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) & [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/q/218384/418556) – Andrew Thompson Jan 12 '16 at 06:33
  • Hi DANA. Welcome to StackOverflow. I hope you find as much use out of it as I have. Just as an FYI, please take a look through this page on refactoring your questions to get the best answers: http://stackoverflow.com/help/how-to-ask I hope it's useful. – entpnerd Jan 12 '16 at 06:55
  • Based on the code snippet, I'd "guess" that `text_1` is `null` – MadProgrammer Jan 12 '16 at 07:14
  • so why when i try to get from textBox it works? and how can i fix this? – DANA Jan 12 '16 at 07:16
  • In the future, consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This is not a code dump, but an example of what you are doing which highlights the problem you are having. This will result in less confusion and better responses – MadProgrammer Jan 12 '16 at 07:17
  • My best "guess" would that you are shadowing your variables, creating a instance field called `text_1` is never assigned a value and a local one, which is the one you use to create the UI – MadProgrammer Jan 12 '16 at 07:19

0 Answers0