Solved

AudioClip : NullPointerException

Posted on 1997-05-09
4
345 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
varialbe initialization 11 37
Java: The Public Class Main 4 30
Problem to Alipay 10 42
printf performancy 11 67
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

809 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