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?
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.
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.
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.
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: