ExceptionInInitializerError when trying to run sikuli from Eclipse using JAVA

Asked by Devi Sridharan

Hi All,

I'm trying to execute a sikuli script from Eclipse IDE using JAVA.I'm facing the following Exception.
I have verified the SYSTEM PATH variables.it is being set to C:\Program Files\Sikuli X\libs;C:\Program Files\Java\jre6\bin
I have added sikuli-script.jar as system library in eclipse.I read the thread https://answers.launchpad.net/sikuli/+question/187447 and followed the steps given there.When I run from command prompt it works fine.Am I missing any setting in Eclipse?

my system configurations are OS:Win-7 32-bit machine

StackTrace

java.lang.ExceptionInInitializerError
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Unknown Source)
 at org.sikuli.script.Env.getOSUtil(Env.java:91)
 at org.sikuli.script.ScreenHighlighter.init(ScreenHighlighter.java:180)
 at org.sikuli.script.ScreenHighlighter.<init>(ScreenHighlighter.java:293)
 at org.sikuli.script.Screen.initBounds(Screen.java:105)
 at org.sikuli.script.Screen.<init>(Screen.java:117)
 at GoogleTest.testGoogleSearch(GoogleTest.java:9)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
 at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
 at com.wapmx.nativeutils.jniloader.DefaultJniExtractor.extractResource(DefaultJniExtractor.java:125)
 at com.wapmx.nativeutils.jniloader.DefaultJniExtractor.extractJni(DefaultJniExtractor.java:110)
 at com.wapmx.nativeutils.jniloader.NativeLoader.loadLibrary(NativeLoader.java:43)
 at org.sikuli.script.Win32Util.<clinit>(Win32Util.java:19)
 ... 32 more

Question information

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

Java 7?

Revision history for this message
Devi Sridharan (devishree-90) said :
#2

Java 6

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

Ok, then it might be, that the Eclipse-outside environment is not used, when you run your app from inside Eclipse.

Look for the corresponding option in your project settings: use/copy system environment

Revision history for this message
Devi Sridharan (devishree-90) said :
#4

what kind of project settings need to be changed?can you specify steps also.It will be of great help

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

I have Eclipse Indigo:

-> Project Properties
-> Run/Debug Settings
-> edit your LaunchConfiguration
-> tab Environment

at the bottom "Append ....." must be selected.

If this is the case, the you can try to add to your environment:

SIKULI_HOME as
C:\Program Files\Sikuli X\

(WITH trailing \)

Revision history for this message
Devi Sridharan (devishree-90) said :
#6

Configured Run/Debug settings.but,Still facing the same exception

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

What about specifying SIKULI_HOME ???

Revision history for this message
Devi Sridharan (devishree-90) said :
#8

Added the SIKULI_HOME to Environment variables as you suggested.but still facing the same problem.

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

Are you using the Junit feature of Eclipse?

Just run this snippet as normal Java application:

import org.sikuli.script.*;

public class Test {

 /**
  * @param args
  */
 public static void main(String[] args) throws FindFailed{
  Screen s = new Screen(0);
  System.out.println(s.userCapture());
                new Win32Util;
 }
}

This should display the capture prompt on the primary screen. After making a selection, the program should end without errors

Revision history for this message
Devi Sridharan (devishree-90) said :
#10

I tried running given snippet,it is throwing the following exception.

Exception in thread "main" java.lang.ExceptionInInitializerError
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Unknown Source)
 at org.sikuli.script.Env.getOSUtil(Env.java:91)
 at org.sikuli.script.ScreenHighlighter.init(ScreenHighlighter.java:180)
 at org.sikuli.script.ScreenHighlighter.<init>(ScreenHighlighter.java:293)
 at org.sikuli.script.Screen.initBounds(Screen.java:105)
 at org.sikuli.script.Screen.<init>(Screen.java:98)
 at Ex.main(Ex.java:9)
Caused by: java.lang.NullPointerException
 at com.wapmx.nativeutils.jniloader.DefaultJniExtractor.extractResource(DefaultJniExtractor.java:125)
 at com.wapmx.nativeutils.jniloader.DefaultJniExtractor.extractJni(DefaultJniExtractor.java:110)
 at com.wapmx.nativeutils.jniloader.NativeLoader.loadLibrary(NativeLoader.java:43)
 at org.sikuli.script.Win32Util.<clinit>(Win32Util.java:19)
 ... 8 more

When compiler tries to create Screen object,it is throwing this exception.

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

The crashing line in DefaultJniExtractor.java is:
InputStream in = this.getClass().getClassLoader().getResourceAsStream(resourcename);

where resource name should contain: Win32Util.dll

I have no idea, why this happens in your situation, but I doubt that it has something to do with Sikuli itself.
Usually NullPointerExceptions are caused by programming flaws, but I cannot see any here.

On my Win 7 (I do not have Eclipse on it) running the above snippet with
javac and java
gives no problems.

So it is not possible for me, to debug this further, sorry.

Revision history for this message
Devi Sridharan (devishree-90) said :
#12

I Switched to different version of eclipse,and it solved my problem.Previously i was using Eclipse galileo which has android plug-in installed in it.when i was trying to run sikuli from this eclipse i was getting the above mentioned exception.Then i switched to Eclipse galileo without android plug-in and to my surpise it resolved the issue.I'm not sure of cause for this exception.

Revision history for this message
Devi Sridharan (devishree-90) said :
#13

Thanks to RaiMan.Hope it will help someone.

Revision history for this message
Matt (droppedchange) said :
#14

I was get ExceptionInInitializerError when trying to run sikuli from IntelliJ using JAVA. I was able to fix it by running intelliJ as administrator. See if that helps.