0

My problem is that when I run the following code in Processing my PC restarts..

import java.awt.AWTException;
import java.awt.Robot;

Robot robot;

void setup() {
  size(400, 400);
  try { 
    robot = new Robot();
  } 
  catch (AWTException e) {
     e.printStackTrace();
  }
  robot.mouseMove(screenWidth/2, screenHeight/2);
}

void draw() {
  //println(frameCount);
}

I've tried the same code on another computer and it worked perfectly.. anyone any suggestion?

acidghost
  • 484
  • 4
  • 14
  • Try reinstalling both Java and AWT. In any case, your code is fine, so I'm going to suggest this is moved to SuperUser where you may be able to gain better help. Also, what OS and Java version are you running? – slugonamission Jun 29 '12 at 09:36
  • Java already reinstalled, still doesn't work.. How can I reinstall the AWT? I'm running Ubuntu 12.04 LTS and openjdk-6 – acidghost Jun 29 '12 at 09:44
  • Solved!! :) I've modified the preferences.txt file into ~/.processing folder adding to the field `preproc.imports.list` the `java.awt.*` library and commented the two import clauses in the code. Now it works, but this isn't a good and definitive solution.. – acidghost Jun 29 '12 at 10:28
  • Restart problem has nothing to do with this code.It seems to be a different problem. – Adil Shaikh Jun 29 '12 at 10:28
  • Is there maybe some misconfiguration of java sdk? The problem is only in import clauses. – acidghost Jun 29 '12 at 10:29

2 Answers2

1

You need to use

Robot [whatever name preferably r] = new Robot();

not

robot = new Robot();
  • It doesn't seem plausible that changing what scope the variable is declared in would have any impact on a side effect as massive as "the machine reboots". If you have some reason to believe it's true anyway, this answer would be improved by explaining that. – Jamey Sharp Nov 06 '12 at 21:59
  • As you can see in the upper comments, I solved this by editing the preferences file in the processing folder and commenting the import statements.. But this wasn't a nice and elegant solution.. Any ideas? – acidghost Nov 08 '12 at 15:39
  • Also your suggestion doesn't make any sense because I declared the robot variable as a Robot type in global scope, so I don't have to redeclare it in the setup() function! – acidghost Nov 08 '12 at 15:41
0

Here's how I solved, for future reference.


I've modified the preferences.txt file into ~/.processing folder adding to the field preproc.imports.list the java.awt.* library and commented the two import clauses in the code. Now it works, but this isn't a good and definitive solution..

acidghost
  • 484
  • 4
  • 14