这是我的代码,它的意思是播放一个我放在我的bluej文件夹中的mp3文件,我真的很难用工具箱错误。
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import java.io.File;
import java.net.URI;
import java.net.URL;
public class JavaAudioPlaySoundExample2
{
public static void main(String[] args) {
try {
System.out.print("pls work");
String bip = "Mattashi8bit.mp3";
Media hit = new Media(new File(bip).toURI().toURL().toString());
MediaPlayer mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
} catch (Exception e) {
}
}
}
这是完整的错误
Exception in thread "Thread-29" java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at javafx.application.Platform.runLater(Platform.java:83)
at javafx.scene.media.Media$_MetadataListener.onMetadata(Media.java:541)
at com.sun.media.jfxmediaimpl.MetadataParserImpl.done(MetadataParserImpl.java:120)
at com.sun.media.jfxmediaimpl.platform.java.ID3MetadataParser.parse(ID3MetadataParser.java:237)
at com.sun.media.jfxmediaimpl.MetadataParserImpl.run(MetadataParserImpl.java:103)
如果有人可以解决我如何修复代码的问题,我将非常感激