[2.0.0] Maven project: images cannot be loaded using ...class.getResource("someImage.png") --- crashes with NPE

Asked by syed ali

Uptil version 1.1.3 i was using the following to define images

final Pattern FILE = new Pattern(Main.class.getResource("file.PNG"));

But i tried in 1.1.4 and also in 2.0.0

It returns NPE

java.lang.NullPointerException
 at jarvis.tests.CreateAcpTest.createNewProject(Test.java:23)

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

Sorry for this apparently API-incompatibility.

I will check and fix asap (but will take until later nexct week).

Revision history for this message
syed ali (alii-gator) said :
#2

Thanks for looking into this,
 i have a solution/workaround so i am not blocked.

instead of (which used to work in 1.1.3)
final Pattern FILE = new Pattern(Main.class.getResource("file.PNG"));

I tried this approach and it works
final Pattern FILE = new Pattern(AbstractClassTest.class.getClassLoader().getResource("file.PNG"));

Addition info:
AbstractClassTest is the class where i define all images.

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

thanks for feedback

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

... and what about:

final Pattern FILE = new Pattern(AbstractClassTest.class.getResource("file.PNG"));

Does it work or throw NPE?

Can you help with this problem?

Provide an answer of your own, or ask syed ali for more information if necessary.

To post a message you must log in.