Hello Guest

Problem with WaveData.create()

  • 7 Replies
  • 12360 Views
Problem with WaveData.create()
« on: October 21, 2009, 18:07:41 »
Hi I have some problem with this method. When I'm trying to compile my program I have list of errors:

Code: [Select]
java.lang.NullPointerException
at org.lwjgl.util.WaveData.create(WaveData.java:95)
at org.lwjgl.util.WaveData.create(WaveData.java:112)
at Sound.loadALData(Sound.java:59)
at Sound.execute(Sound.java:121)
at Sound.<init>(Sound.java:41)
at TestKolizji.initGame(TestKolizji.java:93)
at TestKolizji.main(TestKolizji.java:77)
java.lang.NullPointerException
at Sound.loadALData(Sound.java:61)
at Sound.execute(Sound.java:121)
at Sound.<init>(Sound.java:41)
at TestKolizji.initGame(TestKolizji.java:93)
at TestKolizji.main(TestKolizji.java:77)

Fragment of my code:

Code: [Select]
private int loadALData() {
// Load wav data into a buffer.
AL10.alGenBuffers(buffer);

if(AL10.alGetError() != AL10.AL_NO_ERROR){
return AL10.AL_FALSE;
}

WaveData waveFile = WaveData.create("data/di.wav");

AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data, waveFile.samplerate);
waveFile.dispose();

// Bind the buffer with the source.
AL10.alGenSources(source);

if (AL10.alGetError() != AL10.AL_NO_ERROR){
return AL10.AL_FALSE;
}
     

AL10.alSourcei(source.get(0), AL10.AL_BUFFER,   buffer.get(0) );
AL10.alSourcef(source.get(0), AL10.AL_PITCH,    1.0f          );
AL10.alSourcef(source.get(0), AL10.AL_GAIN,     1.0f          );
AL10.alSource (source.get(0), AL10.AL_POSITION, sourcePos     );
AL10.alSource (source.get(0), AL10.AL_VELOCITY, sourceVel     );
   
// Do another error check and return.
if (AL10.alGetError() == AL10.AL_NO_ERROR){
return AL10.AL_TRUE;
} else {
return AL10.AL_FALSE;
}    
}

Thanks for help Jacek :)

Re: Problem with WaveData.create()
« Reply #1 on: October 21, 2009, 21:22:20 »
Java could not find your audio file. Try "./data/di.wav" or "/data/di.wav" or "/absolutepathtobasedir/data/di.wav", depending on where the file actually is.

Re: Problem with WaveData.create()
« Reply #2 on: October 21, 2009, 22:25:08 »
unfortunatelly still the same error  :-[

*

Offline Matzon

  • *****
  • 2242
Re: Problem with WaveData.create()
« Reply #3 on: October 22, 2009, 07:58:19 »
check the path its trying to access - make sure its on the classpath. NPEs are best debugged locally

Re: Problem with WaveData.create()
« Reply #4 on: October 22, 2009, 08:55:22 »
Alternatively, create an InputStream (e.g. new FileInputStream(...) or SomeClass.class.getResourceAsStream(...)) yourself and pass it to WaveData.create(is). That should be easier to debug (and is more flexible later on).

Re: Problem with WaveData.create()
« Reply #5 on: October 22, 2009, 15:51:28 »
I was trying Ciardhub method so I made FileInputStream and it works fine cause java didn't return FileNotFounException but when I was trying to put it into my SoundLoad method the same error appeared. I think it is something that Matzon say but my english is not good and I'm also novice in OpenGL and OpenAL programing so if You have some time Matzon please look at my eclipse Project http://www.sendspace.com/file/djq5ut and write me what I should add to my code or classpath.

Thanks a lot
Jacek  :)

Re: Problem with WaveData.create()
« Reply #6 on: October 22, 2009, 20:48:49 »
you must be running on your SoundTest root folder to get access to the data/files. And Buffers must be .rewind()'ed before to reuse them after a put() or get() call. Either you can rewind all buffers or use the common Buffer.wrap(array[]) function.
I got your files and built a netbeans project which will run the test main() method, then you can here the sound playing.
Then I made the attached .rar, lwjgl jars and the di.wav data are missing so you must copy them into bin/ and data/ resp.

« Last Edit: October 22, 2009, 20:51:04 by broumbroum »

Re: Problem with WaveData.create()
« Reply #7 on: October 22, 2009, 23:04:38 »
Thanks broumbroum for Your effort  :) I did what You suggest to do and I compiled it in eclipse. No errors but I still dont hear music  :-\ I absolutelly don't know what is wrong.. I always attached all lwjgl jars to project and set VM arguments. And all my openGL application was running without any problems.. So its strange...