Sound Code Problem

I am trying to add sound code to my game and have it a snag, When i run my game applet the applet goes blank and an error is shown in the java console:

Trackback:

at SoundClip.load(SoundClip.java:150)



// load the audio file

clip.open(sample);


at SoundClip.(SoundClip.java:76)



// now load the audio file

load(audiofile);


at EightBitOoze.init(EightBitOoze.java:99)



// load the sound effect

beep = new SoundClip("Beep.wav");


The latest version of the source code can be found here.Any assistence in this matter would be greatly appreciated.

Sincerely,

8BitOoze

I think your problem lies in the constructer. You have a call to super(), which would be the constructor of Object. I think you want this(), to call the other constructor of SoundClip, so your clip objects gets created.

Yes as aazimon said, your SoundClip constructor:


public SoundClip(final String audiofile)
{
	super(); //SHOULD BE this();
	load(audiofile);
}

super() should be changed to this();

Your NullPointerException occurs because in your load() method, it makes a call to clip, which has not been initialized since you have incorrectly tried to call the default constructor of SoundClip.

Also a suggestion, why do you use the getAudioClip(URL url) method in Applet? It is more convenient since you are using an applet.

@aazimon thanks, i will apply this to the source code.

@ra4king I am using a custom class instead of the applets getAudioClip(url) method because, first i want to make the game classes as reusable as possible. Second the source code for the game will be availiable so others can learn how i make it and hopefully try to make their own game, so making reusable understandable classes instead of one large lump class will make it easier for others to understand.

Sincerely,

8BitOoze

Reusable is fine but I was only suggesting 1 method call instead of an entire class :slight_smile: