Solved

implementing audio

Posted on 2003-11-04
6
230 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Groovy:unable to resolve class error 2 70
jar file executable 12 43
Java SE 8u111  Lot of stuff broke 11 54
tomcat not starting 6 31
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now