0

Hey I'm trying to implement some sounds in my Java Program. Within Eclipse it works pretty nice, but when I've build it I get the

java.lang.NoClassDefFoundError: sun/audio/AudioStream error.

Following is the code:

    try {
        InputStream music = new FileInputStream(file);
        AudioStream audioStream = new AudioStream(music);

        AudioPlayer.player.start(audioStream);

    }catch(Exception e) {
        Log.append(e.getMessage());
        e.printStackTrace();
    }

Anyone knows what the problem is or how i can fix this?

Jonas Re
  • 93
  • 1
  • 1
  • 10
  • When do you get the error? Where are you running the code, what JVM, what version? – Erwin Bolwidt Apr 22 '18 at 12:41
  • I'm using java jdk & jre 9.0.4. And i get the Error when i'm starting the Exported Runnable jar. When i'm starting with eclipse it works.. – Jonas Re Apr 22 '18 at 12:54
  • 3
    You're using an internal package (sun.audio.*) in JDK9. JDK9 is much stricter about that than earlier releases. You shouldn't use the `sun.audio.*` package; there's an official API in the `javax.sound` package. See also https://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java – Erwin Bolwidt Apr 22 '18 at 13:10

1 Answers1

0

Instead of:

InputStream music = new FileInputStream(file);

try putting:

InputStream music = new FileInputStream(new File (file));

. Also, you might not have put the songs file path in the java code.

Razneesh
  • 1,147
  • 3
  • 13
  • 29