So I've been making a game, and have decided that I want to a sound effects for it. I can play sounds just fine until I package the class files and (and the wav audio files) the into the jar, and only to find that it can't find the files. I am using getClass().getResource("sounds/enemyExplode.wav")
to get the file. Is there a different method that I should be using?
Thanks in advance!
The class loader's getResource() method operates on resources within the class path. If you have the sounds at the following location in the JAR:
/sounds/enemyExplode.wav
Then you need to use a leading slash in front of the path (just as above) in that call.
Remember a JAR file is really nothing more than a packaged up version of the filesystem (same format as a zip) and the class loader operates upon it as it would if it were a filesystem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With