File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes [newbie] Syntax error on token(s), misplaced construct(s) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "[newbie] Syntax error on token(s), misplaced construct(s)" Watch "[newbie] Syntax error on token(s), misplaced construct(s)" New topic
Author

[newbie] Syntax error on token(s), misplaced construct(s)

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

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)


NOTE: The tags don't seem to work for bold.


Jon
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14266
    
  21

Please copy and paste the exact error message that you get, that makes it much easier to help you with this.

NOTE: The tags don't seem to work for bold.

No, ubb tags do not work inside a code block.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14266
    
  21

Aha, I see you edited your post.

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 Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Jesper Young wrote:Please copy and paste the exact error message that you get, that makes it much easier to help you with this.

NOTE: The tags don't seem to work for bold.

No, ubb tags do not work inside a code block.


lol...I had a missing import, now it's working thanks anyway
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [newbie] Syntax error on token(s), misplaced construct(s)