PDA

View Full Version : problem using applet and AudioClip


dsylebee
07-07-2009, 12:56 AM
Hi everyone ive been working on a applet for school project and im getting a null exception, but I can't seem to find it plase help me! :)

here is the compiler result


run:
java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Applet.java:152)
at animalgame.Animals.<init>(Animals.java:58)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:785)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
at sun.applet.AppletPanel.run(AppletPanel.java:368)
at java.lang.Thread.run(Thread.java:619)
BUILD SUCCESSFUL (total time: 1 minute 40 seconds)



here is the code:


package animalgame; // ignore the package il remove it after

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Animals extends JApplet
{
private JButton[] buttons = new JButton[5];
private AudioClip[] sounds = new AudioClip[5];
private String[] animals = new String[5];
private ImageIcon[] images = new ImageIcon[5];
private int current;
JPanel top, low;

public Animals()
{
top = new JPanel();
low = new JPanel();

current = 0;

images[0] = new ImageIcon( getClass().getResource("images/cow.jpg"));
images[1] = new ImageIcon( getClass().getResource("images/dog.jpg"));
images[2] = new ImageIcon( getClass().getResource("images/cat.jpg"));
images[3] = new ImageIcon( getClass().getResource("images/horse.jpg"));
images[4] = new ImageIcon( getClass().getResource("images/bird.jpg"));

animals[0] = "cow";
animals[1] = "dog";
animals[2] = "cat";
animals[3] = "horse";
animals[4] = "bird";

/*for( int i = 0 ; i < 5; i++ )
low.add( new JLabel( animals[i] ) );*/

buttons[0] = new JButton("", images[0]);
buttons[1] = new JButton("", images[1]);
buttons[2] = new JButton("", images[2]);
buttons[3] = new JButton("", images[3]);
buttons[4] = new JButton("", images[4]);

low.setLayout( new GridLayout(1, 5) );

for( int i = 0; i < 5; i++)
low.add( buttons[i] );

add( low );


sounds[0] = getAudioClip( getDocumentBase(), "cow.wav" );
sounds[1] = getAudioClip( getDocumentBase(), "dog.wav" );
sounds[2] = getAudioClip( getDocumentBase(), "cat.wav" );
sounds[3] = getAudioClip( getDocumentBase(), "horse.wav" );
sounds[4] = getAudioClip( getDocumentBase(), "bird.wav" );

}
}