我是JavaFX编码的新手(在IntelliJ思想中),并且一直在阅读/搜索如何在主控制器/容器中交换场景。我在另一个线程(Loading new fxml in the same scene)中找到了珠宝莉的答案,但是在下面的代码中收到了一个错误。
public static void loadVista(String fxml) {
try {
mainController.setVista(
FXMLLoader.load(VistaNavigator.class.getResource(fxml)));
} catch (IOException e) {
e.printStackTrace();
}
}
我收到的错误如下:
Error:(56, 27) java: method setVista in class sample.MainController cannot be applied to given types;
required: javafx.scene.Node
found: java.lang.Object
reason: actual argument java.lang.Object cannot be converted to javafx.scene.Node by method invocation conversion
我知道其他人已经开始工作了,但是我所做的就是创建一个新的项目并复制代码。有谁可以帮我?
发布于 2015-03-26 01:32:22
看起来您正在尝试用JDK1.7编译它:代码只在JDK1.8中工作(这里的区别是JDK1.8中引入的泛型方法的增强类型推断)。
您应该将IntelliJ配置为使用JDK1.8而不是1.7。
如果您想将代码恢复为JDK1.7兼容,可以尝试用
public static void loadVista(String fxml) {
try {
mainController.setVista(
FXMLLoader.<Node>load(VistaNavigator.class.getResource(fxml)));
} catch (IOException e) {
e.printStackTrace();
}
}
(如果需要,可以使用适当的import javafx.scene.Node ;
)。当然,可能还有其他不兼容的地方,因为您使用的代码是针对JDK1.8的。
https://stackoverflow.com/questions/29271985
复制相似问题