In this snippet I think I declared textArea before so why am I getting a syntax error?
Output:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
ActionListener cannot be resolved to a type
at homenetwork.bkr.training.TextComponentFrame.<init>(TextComponentFrame.java:35)
at homenetwork.bkr.training.TextComponentTest$1.run(TextComponentTest.java:14)
at java.awt.event.InvocationEvent.dispatch(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)
ActionListener is in the package java.awt.event, and you're not importing that in your source file. Add this at the top of your source file:
Note that import java.awt.*; does not import everything in package java.awt.event - Java has no subpackages.
The error you get is a little strange, it indicates that you probably have old *.class files lying around. Try deleting them and recompiling everything.
Jon, you're getting quote some "Unresolved compilation problem" runtime errors (also in other threads). That tells me you are using an IDE (Eclipse, Netbeans, etc) to run your code. I suggest you check the IDE's compiler errors before trying to run. Those will tell you, more or less, what's wrong. Don't run your code until all errors have been resolved.
In your case, the error should be something like "ActionEvent cannot be resolved to a type". And Jesper told you the reason (although he mentioned the wrong class).