← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #230722]: [1.0] Receiving ExceptionInInitializerError ... Caused by: java.lang.NullPointerException at org.sikuli.script.Settings.<clinit>(Unknown Source) when using sikuli-script.jar with Jython (standalone or in NetBeans, Eclipse, ...)

 

Question #230722 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/230722

Description changed to:
*** solution/workaround
----------------------------------------------------

This is a general advice, how to use the current sikuli-script.jar with Jython 
... or in NetBeans, ... with Jython

*** For the mentioned error, this is the workaround:
Either use the environment variable SIKULI_HOME 
or the JVM commandline parameter -Dsikuli.Home 
to tell Sikuli the folder that contains the libs folder (and of course sikuli-script.jar ;-)

If you have no chance to add JVM parameters (as e.g. in NetBeans
Python), than you need the following in your main Python script:

import java.lang.System
java.lang.System.setProperty("sikuli.Home", "path-to-the-folder-containing-sikuli-script.jar")
from sikuli import *

This should work, if one of the following setups is used:

*** MANDATORY: 
-- leave all Sikuli stuff in one place 
-- do not copy around any contents  (unless advised by RaiMan ;-)
-- do not unjar sikuli-script,jar 

*** Method 1 --- brute force --- (changes your Jython installation, but works for every project)
- close all Python projects in your IDE and stop any running IDE
- go to your Jython installation folder (the one that is used when running Jython scripts either standalone or with NetBeans, ...)
- rename the folder Lib to e.g. xLib
- rename jython.jar to xjython.jar
- copy sikuli-script.jar to the jython installation folder
- in the jython installation folder rename sikuli-script.jar to jython.jar
- as a last mandatory action delete the cachedir

now your Jython installation uses the content of sikuli-script.jar as
Jython system (which in fact is a version 2.5.4rc1 - but this does not
really matter).

now try either interactively or with a script:
import sys; for e in sys.path: print e

*** Method 2: needed for every project in your IDE (NetBeans, ...)
In your project settings/properties add to the Python path or somehow tell the standalone Jython the following 2 entries on Python path (must be after the entries for the used Jython):
path-to-sikuli-script.jar/Lib
path-to-sikuli-script.jar

At least in Netbeans you will not be able to make the first entry, since you cannot step down into the jar and the entries are only selectable via file chooser. So just leave the first line as
path-to-sikuli-script.jar

Now close your project and close NetBeans.
- Go into your project folder and into folder nbproject
- Edit project.properties with a suitable editor and add /Lib to the first entry of path-to-sikuli-script.jar
- Take care not to insert any blanks, linefeeds or touch the separator character |
- Save the file and close the editor

Now open your IDE and open your Python project.
Now all should be fine.

------------------------------------------------------------------------------------------------

I'm receiving a 'java.lang.ExceptionInInitializerError' when trying to
run Sikuli in Netbeans. Here's my code:

import sys
lib = "C:\\sikuli-script\\Lib"
sys.path.append(lib)
from sikuli import *
popup("test")

Here's the error:

Traceback (most recent call last):
  File "C:\My Documents\NetBeansProjects\Test\src\test.py", line 2, in <module>
    from sikuli import *
  File "C:\sikuli-script\Lib\sikuli\__init__.py", line 3, in <module>
    from Sikuli import *
  File "C:\sikuli-script\Lib\sikuli\Sikuli.py", line 17, in <module>
    from Region import *
  File "C:\sikuli-script\Lib\sikuli\Region.py", line 20, in <module>
    class Region(JRegion):
java.lang.ExceptionInInitializerError

	at org.sikuli.script.Region.<clinit>(Unknown Source)
.......(A ton more errors)
........
Caused by: java.lang.NullPointerException

        at org.sikuli.script.Settings.<clinit>(Unknown Source)

        ... 78 more


java.lang.ExceptionInInitializerError: java.lang.ExceptionInInitializerError


Here's a summary of what I've done so far:

1) Installed 32 bit java (I tried 64 bit but switched to 32 to see if it would help, it doesn't)
2) I have my C:\Program Files (x86)\Java\jre7\bin,C:\Program Files (x86)\Sikuli\libs, C:\sikuli-script\Lib, C:\sikuli-script\ all in my system path variable.
3) I've added a SIKULI_HOME variable and set it to C:\Program Files (x86)\Sikuli\libs
4) I've created a C:\sikuli-script folder that contains C:\sikuli-script\sikuli-script.jar and C:\sikuli-script\Lib
5) I'm using Jython 2.5.3 by default and added C:\sikuli-script\Lib to my Python path.
6) I've added C:\sikuli-script\sikuli-script.jar to my Java path.
7) I've added the following lines to my Jython C:\jython2.5.3\jython.bat

=====
@echo off

set sikuli_jar=C:\sikuli-script\sikuli-script.jar

set CLASSPATH=%sikuli_jar%
set JYTHONPATH=%sikuli_jar%\Lib
=====

All help is appreciated. I'm using Netbeans 7.3, Windows 7 64 bit, JDK
1.7 and JRE 7.

You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.