Newbie: Space Invaders Example, Sound Loading Problem

Started by gnat, October 18, 2010, 09:28:32

Previous topic - Next topic

gnat

Hello, i'm new to LWJGL and am having trouble running the Space Invaders example found in lwjgl-source-*.zip. Note: The basic Game.java example complies and runs fine.

Eclipse console:
QuoteUse -fullscreen for fullscreen mode
Exception in thread "main" java.lang.NullPointerException
   at org.lwjgl.examples.spaceinvaders.SoundManager.addSound(SoundManager.java:157)
   at org.lwjgl.examples.spaceinvaders.Game.initialize(Game.java:250)
   at org.lwjgl.examples.spaceinvaders.Game.<init>(Game.java:182)
   at org.lwjgl.examples.spaceinvaders.Game.main(Game.java:593)

The problem line seems to be:
Game.java:250
SOUND_SHOT   = soundManager.addSound("shot.wav");


My assumption is that Java cannot find "shot.wav". I have placed the res folder in the in the root of the project directory as well as a copy of the data files from res/spaceinvaders in the root of the project directory.

My VM arguments in Eclipse (Properties->Run/Debug Settings->Edit..->Arguments tab->VM Arguments) are as follows:
Quote-cp .;res;jar\lwjgl.jar;jar\lwjgl_test.jar;jar\lwjgl_util.jar; -Djava.library.path=native\windows


I have tried in both Eclipse and Netbeans using LWJGL 2.4.2 and LWJGL 2.5 with the same result. I am running Windows.


Any insight?

broumbroum

Try adding a "/" slash : /shot.wav . Resources are likely to be located into res/spaceinvaders sub folder.

kappa

Had the same issue a while back, put the resources (res folder) in a jar/zip file and add it to the classpath made it work for me.

gnat

No difference with either method.

This is my classpath:
Quote-cp .;res;data.jar;jar\lwjgl.jar;jar\lwjgl_test.jar;jar\lwjgl_util.jar; -Djava.library.path=native\windows

Jar file with data: http://www.geenat.com/files/data.jar

Here is a screenshot:



bobjob

for debugging purposes, just put the wave files in the "src" folder for testing. and make sure to right click on the "Example" project and click on "Refresh".

gnat

Done, and no difference.

[edit]
Solution found, will be posting it shortly. Thank you all for your assistance in narrowing it down!

gnat

Solution

Customizing the classpath as a VM option will NOT work. You must use the IDE's specific facility for customizing the classpath in order for it to handle it properly. (And therefore have Java find your data folder, or "/res" in this case.)


Eclipse
Project->Properties->Java Build Path->Libraries tab->Add Class Folder

Add the /res folder in your project directory (copied from the lwjgl zip).

Note: If your /res folder isn't listed here, you'll have to add it to your project first.

NetBeans
Project Properties->Libraries->Run tab->Add JAR/Folder

Add the /res folder in your project directory (copied from the lwjgl zip).