0

This may have been asked a lot but for some reason, my getResource method could not find the file in my resource folder. The file is in programfolder/resources/images/drag.png. My getResource code is:

SidebarItem.bufferedImage = ImageIO.read(Main.class.getResource("/images/drag.png"));

my classpath is:

<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>

Whenever I run the main class it always throw an exception because it could find the drag.png file. Thanks

MarianD
  • 13,096
  • 12
  • 42
  • 54

1 Answers1

0

Try using this code:

ClassLoader cl = Main.class.getClassLoader();
SidebarItem.bufferedImage = ImageIO.read(cl.getResourceAsStream("images/drag.png"));
Yug Singh
  • 3,112
  • 5
  • 27
  • 52