[Java] getLastMatch() returns null -- has to be used with last searched region

Asked by Saorabh Singh

Hi,
i am using Sikuli in my java program,on windows platform

I am using below code:

Pattern phone1 = new Pattern(imagePath + "android/imgs/Phone.png");
Region r=s.exists(phone1, 2);
if (r!=null)
System.out.println("Phone match %= "+r.getLastMatch());

Phone match %= null
& when i checked value of r it was:Match[901,333 66x31] score=0.88, target=center

Any idea why last match object is null???

Actually i have to get matched% or say Score..
As i am unable/not allowed to use r.getscore() function...

So m using it in this way... r.getLastMatch().getScore()
but this statement throws Exception(NULL POINTER)

Help me out

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
Best RaiMan (raimund-hocke) said :
#1

the getLastMatch() is an attribute of the region that was last searched.

So if you want to use getLastMatch() in yor case, it is
s.getLastMatch()

The other problem:

exists() returns a Match object. So if you want to use getScore, you have to assign the result of exists() to a Match object, since Region objects do not have a score attribute.

Match m = s.exists()
Float sc = m.getscore()

should work.

Revision history for this message
Saorabh Singh (kunnu30) said :
#2

Thanks Raiman