播放音频文件 - 工具包未初始化

时间:2016-01-04 21:39:36

标签: java javafx

我试图在java中播放音频文件,但它说工具包没有初始化,我不确定我想要使用什么工具包,也不知道在哪里初始化它。

public class PianoKey {
        public PianoKey(String keySoundPath, int octaveNumber){
            try{
                Media audioPath = new Media(keySoundPath);
                MediaPlayer audioPlayer = new MediaPlayer(audioPath);
                audioPlayer.play();
            }catch(Exception e){
                System.out.println(e);
            }
        }
    }

钢琴键类:

java.lang.IllegalStateException: Toolkit not initialized

引发

var userChoice = prompt("rock, paper, scissors, rope?").toLowerCase();
while (["rock", "paper", "scissors", "rope"].indexOf(userChoice) === -1) {
    userChoice = prompt("Please choose: rock, paper, scissors, rope?").toLowerCase();
}

alert("You chose '" + userChoice + "'");

0 个答案:

没有答案