このサイトから取得した非常に単純なコードがあります ( senderleの厚意により) mp3 ファイルを再生します (私は を初めて使用しますjavafx
) 。
import javafx.scene.media.*;
public class Start
{
public static void main(String[] args)
{
String bip = "file:/Sounds/sound.mp3";
Media hit = new Media(bip);
MediaPlayer mediaPlayer = new MediaPlayer(hit); // This is line 8 from the Exception
mediaPlayer.play();
}
}
このコードを実行すると、次の例外が発生します。
Exception in thread "main" java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:155)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:150)
at javafx.application.Platform.runLater(Platform.java:52)
at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:450)
at javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:365)
at Start.main(Start.java:8)
これを修正するにはどうすればよいですか?