Solved

implementing audio

Posted on 2003-11-04
6
236 Views
Last Modified: 2013-11-23
For some reason my applet crashes when i try to implement audio
i get an error saying applet notinited

and when i open the java console it says:

java.lang.NullPointerException

      at java.applet.Applet.getCodeBase(Unknown Source)

      at WaterTankThread.<init>(WaterTankThread.java:46)

      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

iv implemented it like so....

........
import java.applet.AudioClip;

public class AudioTest extends Applet implements ActionListener
{
// DATA MEMBERS
      ..........
      
      //sounds
      AudioClip soundVar;
                ...................

public AudioTest()            
      {
            .............
            //register sounds
            soundVar = getAudioClip(getCodeBase(), "sounda.wav"); //if i comment this line the applet will run fine??
0
Comment
Question by:limubai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9683083
You cannot acces getCodeBase() fromm the applet ctor.

Just move your initialisation code into the applets init() method.
0
 

Author Comment

by:limubai
ID: 9683086
OOps, it should say....

java.lang.NullPointerException

     at java.applet.Applet.getCodeBase(Unknown Source)

     at AudioTest.<init>(AudioTest.java:46)

     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
0
 

Author Comment

by:limubai
ID: 9683093
i dont have an init method?
does that mean i must implement an init method just for audio?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 20 total points
ID: 9683124
It's nothing to do with audio. init() is a standard applet method that is called to perform applet initialization.
Before it is called codebase is not defined.

replace your ctor with this:

public void init()          
     {
          .............
          //register sounds
          soundVar = getAudioClip(getCodeBase(), "sounda.wav"); \
    }
http://java.sun.com/docs/books/tutorial/applet/index.html


0
 

Author Comment

by:limubai
ID: 9685264
Thanks for that objects
0
 
LVL 92

Expert Comment

by:objects
ID: 9690772
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question