• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AWTException

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic