Steve Waters
Steve Waters

Reputation: 3548

java.lang.NullPointerException with existing and correct file path

I don't understand why I'm getting:

java.lang.NullPointerException
    at com.sun.media.sound.StandardMidiFileReader.getSequence(Unknown Source)
    at javax.sound.midi.MidiSystem.getSequence(Unknown Source)
    at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
    at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)

Even though the same code works in my another application. The file path is correct, the file is there. I'm clueless.

Relevant code before sound method:

String soundpath = "res/sound.au";
sound(soundpath);

Here's my sound method:

public static void sound(String path){
try {

AudioInputStream audio = AudioSystem.getAudioInputStream(SoundTest.class.getResource(path));
Clip clip = AudioSystem.getClip();
clip.open(audio);
clip.start();

} catch (Exception e) {
System.out.println("Might wanna check: " + path + "\n");
e.printStackTrace();
}

Upvotes: 0

Views: 1316

Answers (2)

Nikolay Shmyrev
Nikolay Shmyrev

Reputation: 25220

This error occurs when you try to create an AudioInputStream from a null URL.

Upvotes: 0

Robin Green
Robin Green

Reputation: 33083

The file needs to be on your CLASSPATH. Is the CLASSPATH set appropriately in both applications?

Upvotes: 2

Related Questions