Solved

AudioClip : NullPointerException

Posted on 1997-05-09
4
353 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
[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
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
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…
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…
Suggested Courses

734 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