Solved

implementing audio

Posted on 2003-11-04
6
224 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
Comment Utility
You cannot acces getCodeBase() fromm the applet ctor.

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

Author Comment

by:limubai
Comment Utility
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
Comment Utility
i dont have an init method?
does that mean i must implement an init method just for audio?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 92

Accepted Solution

by:
objects earned 20 total points
Comment Utility
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
Comment Utility
Thanks for that objects
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bunnyEars2 challenge 6 66
array11 challenge 16 51
strCopies  challenge 17 73
micro services vs rest web services 16 45
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

743 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

17 Experts available now in Live!

Get 1:1 Help Now