• Post Reply Bookmark Topic Watch Topic
  • New Topic

AWTException  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to experiment with a code I was writing using the Robot class. However, when I try to instantiate a robot object I get an error message saying unhandled exception type AWTException. Can anyone explain what this means/ how to get rid of it?
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to do something like



Exception handling is a fairly fundamental Java concept, which you can learn about here. For this reason, I'm moving this to our Java in General (Beginner) forum for any followup.
 
Edward Mulligan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd tried doing that before I came here. However, when I surround it with try/catch all that happens is later on in the program when I call on the robot variable I'm told it can't be resolved.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just wrap it in a try/catch block but do nothing to handle the error in the catch block, then you're always going to have problems later down the line if you attempt to do something that depends on the code in the try block completing successfully.

In the case of creating a Robot, if you get an AWTException as you have, remember that this means no Robot was created so you can't rely on it later.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to take away from what Craig says, I think that Edward's problem is something simpler -- a scope issue. This doesn't work:



In Java, a set of curly braces defines a "scope". Variables declared inside a scope are available only in that scope; outside the scope, they don't exist. There are two general strategies for dealing with this. Number 1:



And number 2:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!