• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Java Applet & Sound

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm implementing a java applet that will play a sound file that is of a .wav format. I'm using the state design pattern and I am having a really difficult time getting my audio clips to play. I keep getting a NullPointerException when I call getDocumentBase(). Here is the Code that I have:

//Rick Katka
//May 4, 2005
//CSCI 471-Final Project
//JApplet wav file media player

///////////////////Needed for GUI//////////////////////
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.applet.Applet.*;

////////////////////////Applet Driver///////////////////////
public class JApplet_MediaPlayer extends JApplet implements ActionListener
//references to buttons in the GUI

private JButton jbutton_play, jbutton_pause, jbutton_stop;
private JButton jbutton_search;
private MediaPlayer_LoadingState ls;
private AudioClip sound1;//wave file variable

//creates a new reference to the context class
MediaPlayer_Context context = new MediaPlayer_Context();

//init like constructor
public void init()
//super("Wave MediaPlayer");

//create a new instance of all buttons
jbutton_play = new JButton();
jbutton_pause = new JButton();
jbutton_stop = new JButton();
jbutton_search = new JButton();

//sets the applets layout
getContentPane().setLayout(new BorderLayout(3,3) );

///////////////////play button/////////////////////
//adds the play button to the left side of the applet

//add text to the button

//add an action listener to the button

//////////////////pause button//////////////////////
//adds the play button to the left side of the applet

//add text to the button

//add an action listener to the button

//////////////////stop button//////////////////////
//adds the play button to the left side of the applet

//add text to the button

//add an action listener to the button

//////////////////Search button//////////////////////
//adds the play button to the left side of the applet

//add text to the button

//add an action listener to the button

//set size
//set visible

}//end init constructor

public void actionPerformed(ActionEvent e)
if(e.getActionCommand().equals("SEARCH") )
if(e.getActionCommand().equals("PLAY") )
else if(e.getActionCommand().equals("PAUSE") )
else if(e.getActionCommand().equals("STOP") )

}//end action performed

public void setSound(AudioClip s)
sound1 = s;

public void setMyAudioClip(String s)
System.out.println("Here in setMyAudioClip " + s);
//***********MY ERROR IS HERE*******************
sound1 = getAudioClip (getDocumentBase(), s );

public void playDaSounds()
sound1.play();//plays the sound
}//end JApplet_MediaPlayer

Thanks for Any Help!! I need it. This is really bugging me.

Rick J. Katka
Sophomore, Carthage College
[ May 16, 2004: Message edited by: Gregg Bolinger ]
Ranch Hand
Posts: 15304
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, I edited your post and removed Urgent from the subject line. There are no posts here more important or urgent than the next persons, so no need to shout.

Secondly, this forum is for general questions about java for beginners. Your question is a little more specific so I am going to move it to the Applets forum where those guys can help you out.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic