hello,
i used to do this when i want to load an image into the game
1 2 3
| String path = "D:/My Graphics/hero.png"; ImageIcon ii = new ImageIcon(path); Image image = ii.getImage(); |
but when i tried to export the project into a Runnable Jar and test it in another pc, everything disappeared, and it make sense cause the other computers doesn't have that path
so i did some research and tried this :
1 2 3 4 5 6 7 8 9 10
| String img = "graphics/hero.png"; Image image; URL path = this.getClass().getResource(img); if (path != null) { ImageIcon ii = new ImageIcon(path, "hero"); image = ii.getImage(); } else { System.err.println("Couldn't find file: " + path); } |
it always print the error and i don't get my image
this is a screen of my work space
thank you