ExceptionInInitializerError being thrown when creating Screen instance

Asked by Kevin Anderson

Hello,

I am new to using sikuli and was able to create 1 project fairly easy with it but now I can't get it to work. As soon as Screen s = new Screen(); is hit I get the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
 at ControlMeasureCreation.getCoordinates(ControlMeasureCreation.java:20)
 at Toolkit$18.actionPerformed(Toolkit.java:486)
 at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
 at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
 at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
 at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
 at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
 at java.awt.Component.processMouseEvent(Unknown Source)
 at javax.swing.JComponent.processMouseEvent(Unknown Source)
 at java.awt.Component.processEvent(Unknown Source)
 at java.awt.Container.processEvent(Unknown Source)
 at java.awt.Component.dispatchEventImpl(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
 at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
 at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Window.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
 at java.awt.EventQueue.access$500(Unknown Source)
 at java.awt.EventQueue$3.run(Unknown Source)
 at java.awt.EventQueue$3.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
 at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
 at java.awt.EventQueue$4.run(Unknown Source)
 at java.awt.EventQueue$4.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.IllegalThreadStateException: Cannot call method from the event dispatcher thread
 at java.awt.Robot.checkNotDispatchThread(Unknown Source)
 at java.awt.Robot.waitForIdle(Unknown Source)
 at org.sikuli.script.Mouse.move(Mouse.java:345)
 at org.sikuli.script.Mouse.move(Mouse.java:318)
 at org.sikuli.script.Mouse.init(Mouse.java:59)
 at org.sikuli.script.Screen.initScreens(Screen.java:89)
 at org.sikuli.script.Screen.<clinit>(Screen.java:58)
 ... 38 more

Here is my code:

import org.junit.Before;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
import org.junit.After;

public class ControlMeasureCreation {

 Toolkit t = new Toolkit();

 @Before
 public void setUp() {

 }

 public void getCoordinates(String coor) {

  Screen s = new Screen();

  Pattern p;

  try {

   p = new Pattern("images/CMCreation/add.png");
   s.find(p.similar(0.95f));
   s.click(p.similar(0.90f));// click add

   p = new Pattern("images/CMCreation/add.png");
   t.lblPassFail.setText("Pass");

  } catch (FindFailed e) {
   t.lblPassFail.setText("Fail");
  }

 }

 @After
 public void tearDown() {

  System.exit(0);

 }

}

I have been unable to find any fixes via google but this site keeps coming up so I'm hoping there is someone that could help me.

Thank you.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Toolkit t = new Toolkit();

... for what is that? not needed for SikuliX.

t.lblPassFail.setText("Pass");

seems to be some Java-based GUI, that you try to operate from a thread, that uses SikuliX features.

If you want to use SikuliX features in a GUI based environment (EventDispatchQueue), you have to take care, that the SikuliX features (Java AWT based) are run in another thread.

Revision history for this message
Kevin Anderson (kevin-anderson-k) said :
#2

RaiMan,

Thank you. Running Sikuli on it's own thread worked.

Revision history for this message
Kevin Anderson (kevin-anderson-k) said :
#3

Thanks RaiMan, that solved my question.