CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Unhappy Error in ActionListener

    Hi Guys,
    Anyone can help me please??

    I am newbie in Java and I tried simple ActionListener and I got an error "Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
    symbol: variable item1.

    I created the item1 as JTextField already but it seem it didn't detected.

    Attached the code :
    public DemoForm() {
    super ("Entry Form");
    setSize(255,80);
    setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    setLayout(new FlowLayout());

    JLabel LabelNumberOfCustomer = new JLabel("Number of the customer : ", JLabel.RIGHT);
    add (LabelNumberOfCustomer);
    setVisible(true);
    LabelNumberOfCustomer.setToolTipText("This is tool tip text");

    JTextField item1 = new JTextField (3) ;
    add (item1);
    theHandler handler = new theHandler();
    item1.addActionListener(handler);
    }

    private class theHandler implements ActionListener {

    public void actionPerformed (ActionEvent event){
    String string = "";

    if (event.getSource()==item1){
    string = String.format("Number of Customer : %s", event.getActionCommand());
    }
    JOptionPane.showMessageDialog(null, string);
    }

    }

  2. #2
    Join Date
    May 2005
    Location
    San Antonio Tx
    Posts
    44

    Re: Error in ActionListener

    its hard to trace the error you are mentioning because your code seems incomplete

    for example your method DemoForm is outside the scope of any class and then you have class thehandler that implements actionListener

    basically you just have this:

    Code:
    DemoForm()
    
    class handler{
        actionPerformed()
    }
    when you should have something like this:
    Code:
    class form{
        demoForm()
    }
    
    class handler{
        actionPerformed()
    }
    
    //and a main method withing a tester class to test your form and handler Class
    class testClass{
        public static void main(String[] args) {
            //code use for testing
        }
    }

  3. #3
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Error in ActionListener

    Please post the whole class remembering to use code tags.

    The error message shown is a run time error saying the code could not be compiled which suggests you are attempting to run an invalid class ie the last compile cycle failed. Are you sure you successfully compiled the class after your last changes?

    BTW are you using an IDE or compiling and running from the command line.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured