当我尝试从mp3获取图像时,我发现了异常。
public MediaPlayer mediaPlayer;
public Media media;
public MediaView mediaView;
public ImageView albumPicture;
public void initialize() {
media = new Media(new File("res\\music.mp3").toURI().toString());
media.getMetadata().addListener(new MapChangeListener<String, Object>() {
@Override
public void onChanged(Change<? extends String, ?> c) {
if (c.wasAdded()) {
if ("image".equals(c.getKey())) {
albumPicture.setImage((Image)c.getValueAdded());
}
}
}
});
mediaPlayer = new MediaPlayer(media);
线程“JavaFX Application Thread”中的异常java.lang.NullPointerException at sample.Controller $ 1.onChanged(Controller.java:67) at com.sun.javafx.collections.MapListenerHelper $ SingleChange.fireValueChangedEvent(MapListenerHelper.java:163) at com.sun.javafx.collections.MapListenerHelper.fireValueChangedEvent(MapListenerHelper.java:72) at com.sun.javafx.collections.UnmodifiableObservableMap.callObservers(UnmodifiableObservableMap.java:65) at com.sun.javafx.collections.UnmodifiableObservableMap.lambda $ new $ 30(UnmodifiableObservableMap.java:59) 在javafx.collections.WeakMapChangeListener.onChanged(WeakMapChangeListener.java:88) at com.sun.javafx.collections.MapListenerHelper $ SingleChange.fireValueChangedEvent(MapListenerHelper.java:163) at com.sun.javafx.collections.MapListenerHelper.fireValueChangedEvent(MapListenerHelper.java:72) at com.sun.javafx.collections.ObservableMapWrapper.callObservers(ObservableMapWrapper.java:115) at com.sun.javafx.collections.ObservableMapWrapper.put(ObservableMapWrapper.java:173) 在javafx.scene.media.Media.updateMetadata(Media.java:525) 在javafx.scene.media.Media.access $ 200(Media.java:78) 在javafx.scene.media.Media $ _MetadataListener.lambda $ onMetadata $ 10(Media.java:544) at com.sun.javafx.application.PlatformImpl.lambda $ null $ 173(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda $ runLater $ 174(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher $ Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda $ null $ 148(WinApplication.java:191) 在java.lang.Thread.run(Thread.java:748)