toemass
YaBB Newbies
Offline
Posts: 3
nullPointer thrown for every call to Robot object
Aug 19th , 2006, 3:22pm
Hi - i'm kind of new to processing and Java though done some object oriented stuff in Actionscript 2.0. I'm trying to take control of the mouse cursor in windows xp, using the Robot class in java (see: http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Robot.html ). I've written a test applet based on one of the example sketches, and i've created a new Robot object ok i think (i.e. no exceptions thrown), but whenever i make a method call to that object, no matter the method, i get a nullPointer exception. Does anybody have an idea why this might be happening? Many thanks, Thomas. Here is my code... public class testSketchRobot extends PApplet { import java.awt.*; Robot myRobot; Color pixTester; void setup() { size(200, 200); rectMode(CENTER); noStroke(); fill(0, 102, 153, 204); //create new robot - have to use try,catch,finally as Robot constructor can throw exceptions. try{ Robot myRobot = new Robot(); } catch (AWTException e) { System.err.println("awt error thrown");//don't see this } catch (SecurityException e){ System.err.println("SECURITY error thrown");//don't see this either } finally { System.err.println("Robot ok i think");//i do see this } } void draw() { background(255);//from the example sketch - left in just so i can see something working rect(width-mouseX, height-mouseY, 50, 50);//from the example sketch - left in just so i can see something working rect(mouseX, mouseY, 50, 50);//from the example sketch - left in just so i can see something working /*trying robot methods - each one will throw a null pointer exception*/ myRobot.mouseMove(300,300); //myRobot.setAutoDelay(500); //pixTester = myRobot.getPixelColor(mouseX, mouseY); //System.err.println(myRobot.toString()); } }