Null pointer exception using Nifty w/ sound

I’m trying to add sound to my nifty GUI. When I add this line to my xml, I get a null pointer exception:

registerSound filename=”menu/Assets/Sounds/tada.wav” id=”tada”

Any suggestions? I have tried both OGG and WAV files. I know the asset is being located, because when when the asset can’t be located the error is different.

How can I post my xml in this thread? The java brackets clear out my xml. Here is the error:

Feb 11, 2013 1:14:08 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.RuntimeException: java.lang.NullPointerException
at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:576)
at de.lessvoid.nifty.Nifty.fromXml(Nifty.java:479)
at menu.ScreenControllerStart.initialize(ScreenControllerStart.java:57)
at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:225)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:255)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:238)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.jme3.niftygui.SoundHandleJme.(SoundHandleJme.java:49)
at com.jme3.niftygui.SoundDeviceJme.loadSound(SoundDeviceJme.java:58)
at de.lessvoid.nifty.sound.SoundSystem.addSound(SoundSystem.java:45)
at de.lessvoid.nifty.loaderv2.types.RegisterSoundType.materialize(RegisterSoundType.java:12)
at de.lessvoid.nifty.loaderv2.types.NiftyType.create(NiftyType.java:109)
at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:569)

<!-- +++++++++++++++++++++++++++++++++++++++  -->
<!-- START MENU SCREEN -->
<!-- +++++++++++++++++++++++++++++++++++++++  -->

<!--MAIN MENU-->

The error occurs with registerSound id=“music” filename=“menu/Assets/Sounds/spacetheme1.ogg” /

Here’s a little more info. I work primarily in eclipse. Just for giggles, I transferred all my code into the jmeSDK to see if the result is different. It’s not. So what am I doing wrong?

INFO: registerEffect [0]
java.lang.NullPointerException
at com.jme3.niftygui.SoundHandleJme.(SoundHandleJme.java:50)
at com.jme3.niftygui.SoundDeviceJme.loadSound(SoundDeviceJme.java:59)
at de.lessvoid.nifty.sound.SoundSystem.addSound(SoundSystem.java:45)
at de.lessvoid.nifty.loaderv2.types.RegisterSoundType.materialize(RegisterSoundType.java:12)
at de.lessvoid.nifty.loaderv2.types.NiftyType.create(NiftyType.java:109)
at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:528)
at de.lessvoid.nifty.Nifty.fromXml(Nifty.java:438)
at menu.ScreenControllerStart.initialize(ScreenControllerStart.java:57)
at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:219)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:249)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:238)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)

Unfortunately I don’t play sounds from nifty so I can’t really help. From what I do remember your xml syntax in the onStartScreen looks wrong, you should check it against the Nifty manual, as said it’s not an area I really know very well tho so I could be way off.

If I delete the onStartScreen effect block, but leave registerSound intact, I still get the null point exception.

EDIT
In other words, the error is caused by “registerSound”. The manual doesn’t cover this. :frowning:

It’s used heavily in the nifty examples supplied with jmeSDK. But I can’t find much documentation to go with it.

This is an excerpt of nifty-examples.jar/all/intro.xml. It works just fine there.

@Asharad said:

The error occurs with registerSound id=“music” filename=“menu/Assets/Sounds/spacetheme1.ogg” /

This has the smell of a wrong path / bad file name.

My guts tell me it should be “Sounds/spacetheme1.ogg”

I used to use sound with Nifty and I can’t say I’ve had any error except my own. So I very highly suspect either your path or file name (capitalization?) is wrong.

Nope the path is correct. If I use the wrong path, instead of a null pointer exception, I get “AssetNotFoundException”

Feb 11, 2013 5:43:12 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.RuntimeException: com.jme3.asset.AssetNotFoundException: Sounds/spacetheme1.ogg (Buffer)
at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:576)
at de.lessvoid.nifty.Nifty.fromXml(Nifty.java:479)
at menu.ScreenControllerStart.initialize(ScreenControllerStart.java:57)
at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:225)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:255)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:238)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Unknown Source)
Caused by: com.jme3.asset.AssetNotFoundException: Sounds/spacetheme1.ogg (Buffer)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:277)
at com.jme3.audio.AudioNode.(AudioNode.java:140)
at com.jme3.audio.AudioNode.(AudioNode.java:152)
at com.jme3.niftygui.SoundDeviceJme.loadSound(SoundDeviceJme.java:56)
at de.lessvoid.nifty.sound.SoundSystem.addSound(SoundSystem.java:45)
at de.lessvoid.nifty.loaderv2.types.RegisterSoundType.materialize(RegisterSoundType.java:12)
at de.lessvoid.nifty.loaderv2.types.NiftyType.create(NiftyType.java:109)
at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:569)
… 9 more

I have found I can make this work, if I point to assets in the nifty-examples.jar file. But if I point to my own assets, I get null pointer. hmmmm…

Question then.

Tell me why the XML in the picture above shows the “registerSound” with a path of “sound/filename.ogg” (which works) while that other one is “menu/Assets/Sounds/spacetheme1.ogg” (doesn’t work)?

@madjack said: Question then.

Tell me why the XML in the picture above shows the “registerSound” with a path of “sound/filename.ogg” (which works) while that other one is “menu/Assets/Sounds/spacetheme1.ogg” (doesn’t work)?

“sound/filename.ogg” is the path to assets located in the library file nifty-examples.jar

“menu/Assets/Sounds/spacetheme1.ogg” is the path to assets in my project.

That works in my environment:

|registerSound id="beep" filename="Sounds/Effects/beep.ogg" /|
|registerSound id="beep2" filename="Sounds/Effects/beep2.ogg" /|

What’s the full path to your asset files?

By default the assets path for a project is defined like so: (jme installed dir)~assets~Sounds~etc But you never use the full path, only the path after “assets”.

Could that be the problem? Capitalization is important too! If that’s not the problem then I give up. Sounds, like the above, have worked fine here for the longest time.

I fixed it. My screencontroller was poorly written. Instead of calling my nifty display from simpleInitApp, I was calling nifty from within an AbstractAppState (which was also my screencontroller).

Yes, I’m learning. :slight_smile:

Oh I get it now… :facepalm:

Your assetManager was null when trying to load the sound file. :confused: Duh.

Sorry for the confusion. I’m still quite lost, but less so now than before.

So it appears that the nifty playSound method lacks volume control. Looks like I’ll be better off handing sound in the jM audioNode instead. :frowning:

Yeah, I dabbled with nifty sound a bit but as soon as I get seriously into it all that got ripped out and went into audio nodes.

@zarch said: Yeah, I dabbled with nifty a bit but as soon as I get seriously into it all that got ripped out and went with something else.

There, I fixed it for you. :wink: