No sound after export to jar

前端 未结 1 1283
一整个雨季
一整个雨季 2021-01-18 19:38

I have problem with my app. When I run app in Eclipse, sound played well, but if I export app to runnable jar, sound doesn\'t work.

Method, where sound is played:

1条回答
  •  囚心锁ツ
    2021-01-18 20:10

    The problem is in this

    AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("sound.wav"));
    

    in JAR file isn't working getResourceAsStream for any reason. So I replace it with getResource:

    AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResource("sound.wav"));
    

    and this works fine.

    0 讨论(0)
提交回复
热议问题