[1.1.14 Jython] App() crashes with Java NPE --- sikulixapi.jar MUST be on Java classpath

Asked by Dirk Schiller

My Script:
========
# sandbox.py

import sys
sys.path.append('sikulixapi.jar')
from org.sikuli.script import App
app = App('test') << Here the Script crashes
app.open()

Used Versions:
============
Jython 2.7.0
SikuliXApi.jar Version 1.1.4
Windows 10

Stack Trace:
==========
C:\_Daten\Work\Coding\Jython\SikuliX>C:\jython2.7.0\bin\jython sandbox.py
Traceback (most recent call last):
  File "sandbox.py", line 4, in <module>
    app = App('test')
        at org.sikuli.script.RunTime.init(RunTime.java:516)
        at org.sikuli.script.RunTime.get(RunTime.java:384)
        at org.sikuli.script.RunTime.get(RunTime.java:221)
        at org.sikuli.script.RunTime.get(RunTime.java:215)
        at org.sikuli.script.RunTime.loadLibrary(RunTime.java:951)
        at org.sikuli.natives.WinUtil.checkFeatureAvailability(WinUtil.java:119)
        at org.sikuli.script.App.<init>(App.java:310)
        at org.sikuli.script.App.<init>(App.java:315)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:211)

java.lang.NullPointerException: java.lang.NullPointerException

Research:
========
When I execute those Steps from the Script ( sandbox.py ) within the Jython Console it still works after a second attempt. On the first try it also crashes with NullPointer Exception.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Dirk Schiller (dschiller) said :
#1

Found a Solution. Not happy with that but it works.

Possible Solution:
==============
# sandbox.py

import sys
sys.path.append('sikulixapi.jar')
from org.sikuli.script import App
try:
    app = App('test')
except:
    pass
finally:
    app = App('test')
app.open()

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

Due to the special relation between the Python API level and the Java API level (historical reasons), your approach does not lead to a correct initialization.

your "solution" apparently triggers the initialisation only in the second try.

you might try:

Screen() # just to trigger the initialization

before doing something else with SikuliX.

The next days I will setup a Python/pyjnius environment myself and also test the plain Jython environment.

I will fix possible startup oddities asap.

BTW: thanks for the testing, evaluation and documentation.

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

I made some tests with different scenarios.

--- pyjnius
In the current shape of SikuliX it is not useable with jnius from Python.
I now have it on the list to make it useable though.
Might take a while, but seems to be worth it

--- plain Jython
The sikulixapi.jar MUST be on the Java classpath (environment CLASSPATH) at time of first use of any SikuliX feature.
Simply having it on sys.path does not work (causes the NPE with App("test") as mentioned above)

Can you help with this problem?

Provide an answer of your own, or ask Dirk Schiller for more information if necessary.

To post a message you must log in.