Web Applet and Sounds


Whenever I try to get a sound to play in web applet version of my game, the game crashes with the following error.

[java]Exception in thread "LWJGL Renderer Thread" java.lang.NullPointerException

at com.StarSearch.Screen.MiniGames.MiniGame.UpdateCountDown(MiniGame.java:321)

at com.StarSearch.Screen.MiniGames.MiniGame.Update(MiniGame.java:426)

at com.StarSearch.Screen.MiniGames.LostProbeScreen.update(LostProbeScreen.java:25)

at com.StarSearch.View.Screen.updateScreen(Screen.java:200)

at com.StarSearch.View.ScreenManager.update(ScreenManager.java:317)

at com.Main.update(Main.java:179)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglCanvas.runLoop(LwjglCanvas.java:225)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:203)

at java.lang.Thread.run(Unknown Source)[/java]

Here is my code that initialises my Audio Node.

[java]countDownNumber = new AudioNode(assetManager, "Screens/MiniGames/Common/Sounds/count_down_number.ogg", false);



Here is the code that plays the sound, and the line where the game crashes.


Everything works fine in the desktop / windows version of the game. I have tried the sound in both .ogg and .wav formats and I have tried different sounds. The applet is signed.

Any suggestions as to what is going on?

Kind regards,


I can only say that i play .oggs in an unsigned applet. So chances are pretty high it’s something in your code. Try printing out some stuff, and see if you can find out where it goes wrong.

Thanks for the quick reply.

I did some tests as you suggested and it seems as though my audioRenderer is always null in the Web version and this is causing the crash. In the Desktop version it works fine. I have no idea what is causing this behaviour.

I also tried doing the example at https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_audio#d_audio_listener

But I found I had the same result. Works perfectly in Desktop mode, but crashes with audioRenderer being null in the Web applet.

I feel like I must be missing something fundamental. :S

Any suggestions?



It seems like you’re missing some libraries?

Are you using the JOAL audio renderer or LWJGL?


I think i know what it is.

It’s the lwjgl thread that takes longer to start in a web applet. While your main thread rushes on and tries to load the sounds, the lwjgl thread has not yet initialized the AudioManager. I solved this by creating a while loop that checked for audio manager (and asset manager as well i think), sleeping the thread for a bit if they were “null”.

Thanks for the reply. I tried what you said but with no luck.

[java]while (audioRenderer == null || assetManager == null)






catch (Exception e)



System.out.println("still null");


I get stuck in an infinite loop of the audioRenderer being null.

I tested the sound on a couple of other machines to ensure it was not a hardware issue. Still doesn’t work.

For anyone who is interested, the “fix” I came up with is to periodically check whether or not the audioRenderer is still null. If it is null, I set a bool to false. Whenever I try to play a sound, I check the bool first. This way I avoid crashes and also, if the audioRenderer does become active at some point, the game will suddenly get sounds.

Though I think for the final release version I’ll probably just cut the sounds as they aren’t super important for my particular game.

Thanks everyone for your assistance!