Solved

AudioClip : NullPointerException

Posted on 1997-05-09
4
328 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:breizh
  • 2
4 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220310
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?
0
 

Author Comment

by:breizh
ID: 1220311
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.

0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220312
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.

0
 

Accepted Solution

by:
jpzwarte earned 100 total points
ID: 1220313
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;

        try
        {
            fis_sound = new FileInputStream(args[0]);
            System.out.println("Playing sound...");
            AudioPlayer.player.start(fis_sound);
            while (true)
            {
            }
        }
        catch (Exception e)
           System.out.println(e);
    }
}
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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 …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

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

10 Experts available now in Live!

Get 1:1 Help Now