1.1.4 collectWords() raises java NPE --- fixed buils#286

Asked by Mindaugas on 2019-04-17

Greetings,

I have a simple python methods call: print(">>" + collectWordsText()). It throws an exception (below).
I'm not sure if I'm using this correctly however - this method seems to be a static method of a Region class,
and I presume it uses implicit region this creating a new region via a constructor is not needed?

If so, could this error indicate some problem with reflection? I'm using java8, sikullx w/ jython 1.1.4-SNAPSHOT build 277

[log] CLICK on L[505,510]@S(0) (525 msec)
[error] script [ add_neoload_monitor_pid ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\add_neoload_monitor_pid.sikuli\add_neoload_monitor_pid.py", line 28, in <module>
    print(">>" + collectWords())
        at org.sikuli.script.Region.findWords(Region.java:2830)
        at org.sikuli.script.Region.collectWords(Region.java:4980)
        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)
java.lang.NullPointerException: java.lang.NullPointerException

[debug] RunTimeAPI: ***** running cleanUp *****

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2019-04-18
Last query:
2019-04-18
Last reply:
2019-04-18
Mindaugas (m1nda5) said : #1

I have another script that fails, different error, but similar issue:

Settings.OcrTextRead=True
Settings.OcrTextSearch=True

match = find("1555512374529.png")
wait(1)
print(match.getTarget().getX())
print(match.getTarget().getY())
print(match.getW())
print(match.getH())
words = Region(match.getX(), match.getY(), match.getW(), match.getH()).findAllText("Process")
print(words)

#print(match.getText()) # does not even highlight the method as available
# print(">>" + r.collectWords())
# print(">>" + collectWordsText())
) raised: Traceback (most recent call last):
  File "<string>", line 11, in <module>
        at org.sikuli.script.Region.doFindAll(Region.java:3063)
        at org.sikuli.script.Region.access$400(Region.java:23)
        at org.sikuli.script.Region$RepeatableFindAll.run(Region.java:3218)
        at org.sikuli.script.Region$Repeatable.repeat(Region.java:3126)
        at org.sikuli.script.Region.findAll(Region.java:2565)
        at org.sikuli.script.Region.findAllText(Region.java:2807)
        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)
java.lang.NullPointerException: java.lang.NullPointerException

The fact that it fails on line: https://github.com/RaiMan/SikuliX1/blob/master/API/src/main/java/org/sikuli/script/Region.java#L3063

indicates that it did not find a match. Would lowering a matching threshold help? How to deal with this situation in general? Should I retry in a loop and with each iteration of the loop I should decrease the match threshold?

RaiMan (raimund-hocke) said : #2

Sorry for the inconvenience. I will come back on this in the next 24 hours (night in europe now :-)

Mindaugas (m1nda5) said : #3

No worries and not too much rush! Thanks for looking into this!

Best RaiMan (raimund-hocke) said : #4

The NPE problem is fixed.

collectWords, collectWordsText now return an empty list if no details are to be returned.

more comments:

# no longer needed wirh 1.1.4+
#Settings.OcrTextRead=True
#Settings.OcrTextSearch=True

match = find("1555512374529.png")
wait(1)
print match # instead of
#print(match.getTarget().getX())
#print(match.getTarget().getY())
#print(match.getW())
#print(match.getH())

# a match is a Region, hence:
words = match.findAllText("Process") # instead of
# words = Region(match.getX(), match.getY(), match.getW(), match.getH()).findAllText("Process")
print(words)

--- Would lowering a matching threshold help?
for working with text, there is no match threshhold: either something is read or not.

Mindaugas (m1nda5) said : #5

Thanks a lot RaiMan, I think my problem might be with some libraries missing. I tried this script:

m = find("1555571349032.png")
words = m.findAllText(".jar")
print(words)

Gives this error:
[13894 debug] Jython: ready: version 2.7.1
[error] script [ reading_text ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\reading_text.sikuli\reading_text.py", line 2, in <module>
    words = m.findAllText(".jar")

        at com.sun.jna.Native.open(Native Method)
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:288)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:427)
        at com.sun.jna.Native.register(Native.java:1647)
        at com.sun.jna.Native.register(Native.java:1360)
        at net.sourceforge.tess4j.TessAPI1.<clinit>(TessAPI1.java:41)
        at org.sikuli.script.TextRecognizer.start(TextRecognizer.java:92)
        at org.sikuli.script.Region.doFindAll(Region.java:3037)
        at org.sikuli.script.Region.access$400(Region.java:23)
        at org.sikuli.script.Region$RepeatableFindAll.run(Region.java:3218)
        at org.sikuli.script.Region$Repeatable.repeat(Region.java:3126)
        at org.sikuli.script.Region.findAll(Region.java:2565)
        at org.sikuli.script.Region.findAllText(Region.java:2807)
        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)
java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: The specified module could not be found.

[debug] RunTimeAPI: ***** running cleanUp *****

Do you know if I'm thinking about this error correctly? What could I be missing?

Mindaugas (m1nda5) said : #6

Solved the last one by installing VC++ 2015 and deleting the ...User/AppData/Local/Test4J/win-xxx/ folder.

RaiMan (raimund-hocke) said : #7

ok, good job ;-)

Mindaugas (m1nda5) said : #8

Thanks RaiMan, that solved my question.