简体   繁体   English

找不到适用于addListener( <anonymous ChangeListener<java.time.Duration> &gt;)

[英]No suitable method found for addListener(<anonymous ChangeListener<java.time.Duration>>)

I've trouble with the following code. 我在使用以下代码时遇到麻烦。 It's showing error while implementing the following code section. 实现以下代码部分时显示错误。 It's a code on JavaFX MediaPlayer project. 这是JavaFX MediaPlayer项目上的代码。

mediaPlayer.currentTimeProperty().addListener(new ChangeListener<Duration>() {
            @Override
            public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });

It shows the following error. 它显示以下错误。

C:\Users\User\Documents\NetBeansProjects\Rmedia\src\rmedia\FXMLDocumentController.java:75: error: no suitable method found for addListener(<anonymous ChangeListener<java.time.Duration>>)
        mediaPlayer.currentTimeProperty().addListener(new ChangeListener<Duration>() {
method Observable.addListener(InvalidationListener) is not applicable
  (argument mismatch; <anonymous ChangeListener<java.time.Duration>> cannot be converted to InvalidationListener)
method ObservableValue.addListener(ChangeListener<? super javafx.util.Duration>) is not applicable
  (argument mismatch; <anonymous ChangeListener<java.time.Duration>> cannot be converted to ChangeListener<? super javafx.util.Duration>)

1 error 1个错误

What should I do to fix this? 我应该怎么做才能解决这个问题? Thanks in advance. 提前致谢。

In order to fix this bug, you need to sort out your imports. 为了修复此错误,您需要整理导入内容。 You've imported javafx.util.Duration in some classes, and java.time.Duration in other classes. 您导入javafx.util.Duration在一些类和java.time.Duration其他类。

You need to decide which of these two classes you want to use, and make sure your import statements across all your classes are referring to the same one. 您需要确定要使用这两个类中的哪一个,并确保所有类中的import语句都引用同一类。

You need to import javafx.util.Duration in your controller class instead of java.time.Duration , similar to what Dawood has mentioned. 您需要在控制器类中导入javafx.util.Duration而不是java.time.Duration ,这与Dawood提到的类似。 However, note that there is no "choice" here - JavaFX API uses javafx.util.Duration , and you must follow that. 但是,请注意,这里没有“选择” javafx.util.Duration API使用javafx.util.Duration ,您必须遵循该选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM