java.lang.NullPointerException at com.sun.media.sound.WaveFileReader.getAudioInputStream(Unknown Source) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at MusicList.init(MusicList.java:32) at MusicList.<init>(MusicList.java:21) at GameFrame.<init>(GameFrame.java:82) at GameApp.main(GameApp.java:7)

My guess it it's something simple like your not properly pointing to the file. Try System.out.println(myRoot + "./sounds/jump.wav"); to see if it's what you were expecting. Just creating the File object doesn't test anything, try calling exists() or canRead() on it.Why don't you use pass that file to getAudioInputStream, otherwise your test is irrelevant.

Going back to your original post, you say there are problems with lag. Are you running the play command from its own thread? (Answer should be yes.) Are you trying to play the same cue more than once at the same time? That will probably require special handling.

Also, if two cues are recorded "efficiently" (near the loudest volume that doesn't distort), their combo (both playing at once) could be overdriving your system, and digital distortion is definitely nasty. You might look at setting their volumes to around 50% or somesuch.

[Added as an edit: using File to get a resource doesn't work so well if you ever intend to ship your app as a jar. I just went through that misunderstanding, myself: http://www.java-gaming.org/topics/obtaining-a-usable-url-getfile-from-a-resource/24342/view.html. So, I second the advice from the others here to use the getAudioInputStream method and a relative address. And yes, getting that relative address right can be a pain. An IDE can make it more confusing if you have separate source and class folders.] In my most recent build, I used the file name getAudioInputStream("sounds/jump.wav") and placed the "sounds" folder as a subfolder of the package containing the calling code.]

File doesn't throw an exception if the path isn't correct. It is better to check if the URL returned by getResource(String) is null. That's why you get a NullPointerException, because it returns null and getAudioInputStream throws the NPE.

Your link also doesn't look correct at all. You can't have a period in the middle of a path. You also do not need "myRoot" because you can also pass a relative path, the path being relative to you current working directory.

Notice theat the pathname now is starting with a slash, so its no relative path to your class but absolute from the root of all folders and jars on the classpath. This also means you can zip your resources into the game jar or a separate resources jar when shipping your game.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org