Error when trying to find image using eclipse Java

Asked by Djg

Hi,

I am trying to use Sikuli in Java using Eclipse in windows. When i try to use hover and give the image path i m getting the below exception. I am using the zip version. Not sure what is the problem. Can anyone please help.
I have imported the sikuli-script.jar in the project and test "Type" method, it works fine.

I set the environment variable as below:
SIKULI_HOME=D:\CHNMCT48977L\Setup\Sikuli\Sikuli-X-1.0rc2-win32\Sikuli-X-1.0rc2-win32\Sikuli-IDE
CLASS_PATH=D:\CHNMCT48977L\Setup\Sikuli\Sikuli-X-1.0rc2-win32\Sikuli-X-1.0rc2-win32\Sikuli-IDE\libs
Path=D:\CHNMCT48977L\Setup\Sikuli\Sikuli-X-1.0rc2-win32\Sikuli-X-1.0rc2-win32\Sikuli-IDE\libs

[info] Windows utilities loaded.
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: C:\Users\DJG\AppData\Local\Temp\tmplib\VisionProxy.dll: Can't find dependent libraries
 at java.lang.ClassLoader$NativeLibrary.load(Native Method)
 at java.lang.ClassLoader.loadLibrary0(Unknown Source)
 at java.lang.ClassLoader.loadLibrary(Unknown Source)
 at java.lang.Runtime.load0(Unknown Source)
 at java.lang.System.load(Unknown Source)
 at com.wapmx.nativeutils.jniloader.NativeLoader.loadLibrary(NativeLoader.java:44)
 at org.sikuli.script.Finder.<clinit>(Finder.java:28)
 at org.sikuli.script.Region.doFind(Region.java:769)
 at org.sikuli.script.Region$RepeatableFind.run(Region.java:1160)
 at org.sikuli.script.Region$Repeatable.repeat(Region.java:1131)
 at org.sikuli.script.Region.wait(Region.java:406)
 at org.sikuli.script.Region.find(Region.java:308)
 at org.sikuli.script.Region.getLocationFromPSRML(Region.java:856)
 at org.sikuli.script.Region.hover(Region.java:529)
 at com.test._JMenuBar.actionPerformed(_JMenuBar.java:71)
 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.AbstractButton.doClick(Unknown Source)
 at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
 at javax.swing.plaf.basic.BasicMenuItemUI$Handler.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$000(Unknown Source)
 at java.awt.EventQueue$1.run(Unknown Source)
 at java.awt.EventQueue$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
 at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
 at java.awt.EventQueue$2.run(Unknown Source)
 at java.awt.EventQueue$2.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.AccessControlContext$1.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)

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
j (j-the-k) said :
#1

My first guess is that you don't have libcv2.1 installed, because the image-recognition-library stuff cannot be found.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

@ j-the-k
In Windows and Mac Sikuli distribution contains the needed OpenCV stuff, so this cannot be the cause.

@ the question
In Eclipse, you have to take care, that the internally used environment when running your stuff contains the mentioned environment variables. There is a run option, that copies the external environment.

It seems, that your PATH misses the entry path-to-java/jre6/bin

To check, that Sikuli generally works, do this on command line:

SIKULI_HOME=D:\CHNMCT48977L\Setup\Sikuli\Sikuli-X-1.0rc2-win32\Sikuli-X-1.0rc2-win32\Sikuli-IDE
CLASS_PATH=D:\CHNMCT48977L\Setup\Sikuli\Sikuli-X-1.0rc2-win32\Sikuli-X-1.0rc2-win32\Sikuli-IDE\libs
PATH=%PATH%;D:\CHNMCT48977L\Setup\Sikuli\Sikuli-X-1.0rc2-win32\Sikuli-X-1.0rc2-win32\Sikuli-IDE\libs
java -jar %SIKULI_HOME%\sikuli-script.jar -i

this should open an interactive Sikuli session.

Be aware, that for using interactive capture in Java (Screen.userCapture()), the above mentioned java path entry must be present too.

Revision history for this message
Djg (gdeepakjain) said :
#3

Hi,

Thank I did the the setup as above except for java -jar and was able to find the image but i got an other exception as in point 2 below.

When i did java -jar , i got the below error as in point 1.

Point1:
C:\Users\Deepak_Goutham.ITLINFOSYS>java -jar %sikuli_home%\sikuli-script.jar -i

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Deepak_Gouth
am.ITLINFOSYS\AppData\Local\Temp\jline_.dll: The process cannot access the file
because it is being used by another process
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.load0(Unknown Source)
        at java.lang.System.load(Unknown Source)
        at jline.WindowsTerminal.loadLibrary(WindowsTerminal.java:315)
        at jline.WindowsTerminal.initializeTerminal(WindowsTerminal.java:240)
        at jline.Terminal.setupTerminal(Terminal.java:75)
        at org.python.util.JLineConsole.<init>(JLineConsole.java:69)
        at org.python.util.JLineConsole.<init>(JLineConsole.java:53)
        at org.python.util.JLineConsole.<init>(JLineConsole.java:49)
        at org.python.util.jython.newInterpreter(jython.java:349)
        at org.python.util.jython.run(jython.java:168)
        at org.python.util.jython.main(jython.java:129)
        at org.sikuli.script.SikuliScript.startInteractiveMode(SikuliScript.java
:84)
        at org.sikuli.script.SikuliScript.main(SikuliScript.java:97)
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: Could not initial
ize class com.sun.jna.Native
        at com.sun.jna.Native$DeleteNativeLibrary.unload(Native.java:738)
        at com.sun.jna.Native$DeleteNativeLibrary.run(Native.java:759)

Point 2:
[info] Windows utilities loaded.
[info] Sikuli vision engine loaded.
Exception in thread "AWT-EventQueue-0" 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.Region.hover(Region.java:533)
 at com.imatt.ide._JMenuBar.actionPerformed(_JMenuBar.java:71)
 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.AbstractButton.doClick(Unknown Source)
 at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
 at javax.swing.plaf.basic.BasicMenuItemUI$Handler.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$000(Unknown Source)
 at java.awt.EventQueue$1.run(Unknown Source)
 at java.awt.EventQueue$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
 at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
 at java.awt.EventQueue$2.run(Unknown Source)
 at java.awt.EventQueue$2.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.AccessControlContext$1.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)

Revision history for this message
RaiMan (raimund-hocke) said :
#4

paste the code

Revision history for this message
Djg (gdeepakjain) said :
#5

Hi,

I was trying to play with sikuli and Java swings. Below is the code

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import org.sikuli.script.App;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;

@SuppressWarnings("serial")
public class _JMenuBar extends JMenuBar implements ActionListener{
 JMenuItem iRun=null,iDebug=null,iStop =null;
 Controller controller=null;

 public _JMenuBar(Controller controller){
  this.controller=controller;
  this.createRun();
 }

 @Override
 public void actionPerformed(ActionEvent actionEvent) {
  if(actionEvent.getSource()==iRun){
   Screen s = new Screen();
   try {
    s.hover("./img/SignOn.png");
   } catch (FindFailed e) {
    e.printStackTrace();
   }
  }
 }
 private void createRun(){
  JMenu mFile = new JMenu("Run");
  mFile.setMnemonic(KeyEvent.VK_R);
  add(mFile);
  iRun = new JMenuItem("Run");
  iRun.setMnemonic(KeyEvent.VK_R);
  iRun.addActionListener(this);
  mFile.add(iRun);
 }
}

Revision history for this message
Best RaiMan (raimund-hocke) said :
#6

This seems to be some conflict with using Java.AWT.Robot (used in s.hover() to move the mouse) inside of a swing event handler, but I do not have any knowledge about that.
might be necessary, to dispatch the run in its own subprocess.

But this generally means, that the Sikuli features seems to be accessible now in your environment.
Try to run with this instead of hover:

s.find("./img/SignOn.png").highlight(2)

or

System.out.println( s.find("./img/SignOn.png") )

Revision history for this message
Djg (gdeepakjain) said :
#7

Thanks RaiMan, that solved my question.