• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

AudioClip : NullPointerException

I use jdk 1.0.2 under win95. I use a File object from an application. I use then AudioClip with the File as parameter. The compilation runs well, but when the running, a NullPointerException comes. My File is not null, and the file exists really on my hard disk.  What is the problem ??
Thanks to answer
  • 2
1 Solution
Are you sing code that looks like:

FileInputStream Myfile;
play(getCodeBAse(), MyFile);

If you are, then your problem is that you are sending a File class to the play command and not a String containing the name of your file.

If not, could you post the relevant parts of your code?
breizhAuthor Commented:
Yes, ok for an applet. But the method getCodeBase() does not work in an application ! How can I do this ? My code is :

URL son = new URL ("file:///C:/musique.au");
Audioclip clip = getAudioClip(son);

It is at this last line that the error appears:
java.Lang.NullPointerException at ...getAppletContext.

Thanks to answer me.

from comp.lang.java, Bill Tschumy posted

In order to create a valid Applet when running standalone you need to implement AppletStub and AppletContext. I have not see any code that does this completely enough to get a valid AudioClip. To my knowledge there is no way to play sound from an application without usingthe undocumented (and semi-forbidden) sun.* classes.
Now there is a possible (though unsatisfactoy) work arround.

You could create your application as an applet and then convert it to an application.

It isn't possible to play audio from a 'normal' application but you CAN do it, like this:

import java.io.*;
import sun.audio.*;

class TestAudio
    public static void main(String args[])
        FileInputStream fis_sound;
        int i;

            fis_sound = new FileInputStream(args[0]);
            System.out.println("Playing sound...");
            while (true)
        catch (Exception e)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now