I’m trying to figure out how and why my images will only load in debug in NetBeans, but yet when I execute the JAR file it will fail to load the images. I have tried debugging the code to fix issue within the path, but any altered statements has no effect on it.
Below is code that is generating the issue.
String imagePath = getClass().getResource("/StandardDeck/GameCards/"+ toString() +".png").getPath();
When doing a file.exists() it always returns false.
Thank you for any help!
Your method won’t work once the application is packaged into a JAR file. You won’t access image inside a JAR with
java.io.Fileclass.You need to use getResourceAsStream method
To start working with the image try: