Reputation: 11
I am trying to access a file in my src folder.
skillImage = ImageIO.read(getClass().getResourceAsStream("/flame.png"));
This will produce an exception:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
I've checked that src actually is my source folder (properties -> java build path -> Game/src is listed)
When I'm running it from a jar it works just fine.
Upvotes: 0
Views: 98
Reputation: 34155
Generally, getResourceAsStream(String name)
works for JAR files as well as for unpacked class folders. Please note the following:
"flame.png"
instead of "/flame.png"
as resource nameMake sure, flame.png
is copied to the package output folder (bin/...
) of the class where getClass()
is called:
getClass().getResourceAsStream("flame.png")
:com.example.Foo
containing the code getClass()
, the default location for flame.png
would be src/main/resources/com/example/
:Upvotes: 1