找到了问题。它是ActionEvent类,在import部分中声明的类不是JavaFX类,因此使用正确的类可以使其正常工作。这是最终代码:
package sample;//import java.awt.event.ActionEvent; //This was the error!import javafx.event.ActionEvent;import javafx.scene.control.Label;public class SampleController { public Label helloWorld; public void sayHelloWorld(ActionEvent actionEvent) { helloWorld.setText("Hello World!!"); }}不需要注释。



