Java ImageIO.read (getClass (). GetResource ()) returns null

Line

andImg = ImageIO.read(getClass().getResource("gate_and.png"));

not working with

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null!

I use Eclipse and in navigation mode, under the bin folder, there is a gate_and.png file, assuming the file is in the build path.

In the package explorer view, I have

project / src / view / class is the class that has the code above.

and

project / image / gate_and.png

I right-click on the project folder> build path> link source to add the image folder as the source. Doing this again gives the msg confirmation that the images are already in the source.

I also tried changing gate_and.png to images / gate_and.png and / images / gate _and.png, but since the image gate_and.png is in the bin folder, I think the original is correct.

, , , .

.

Matt

+2
1

, view.random.name,

getClass().getResource("gate_and.png")

/view/random/name/gate_and.png

. , , .

project/images , Eclipse .

/gate_and.png

getClass().getResource("/gate_and.png")

/, , .. .

javadoc.

+3

Source: https://habr.com/ru/post/1524793/


All Articles