无法将javafx.scene.media.MediaView强制转换为javafx.scene.Parent

无法将javafx.scene.media.MediaView强制转换为javafx.scene.Parent,java,video,javafx,media,Java,Video,Javafx,Media,我有一个MediaView,我想播放全屏视频。。我就是找不到我的MediaView的正确家长。。它给了我这个错误 javafx.scene.media.MediaView无法强制转换为javafx.scene.Parent 那是我的fxml文件 <?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import javafx.scene.layout.*?> <?import j

我有一个
MediaView
,我想播放全屏视频。。我就是找不到我的
MediaView
的正确家长。。它给了我这个错误
javafx.scene.media.MediaView无法强制转换为javafx.scene.Parent

那是我的fxml文件

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.media.*?>
<?import javafx.scene.layout.AnchorPane?>


<MediaView fx:id="astrolabe_intro" fitHeight="200.0" fitWidth="200.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="astrolabe.astrolabe_introController" />
不能用作根节点,因为它不从扩展。尝试将您的
MediaView
包装在一个文件夹中。例如:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.media.*?>
<?import javafx.scene.layout.AnchorPane?>


<AnchorPane fx:id="anchorPane" fitHeight="200.0" fitWidth="200.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="astrolabe.astrolabe_introController" >
    <MediaView fx:id="astrolabe_intro"/>
</AnchorPane>


而且

我认为给两个相同的id会将媒体播放器链接到媒体视图,就像说“在此视图上播放该媒体”。。这是错误的吗?是的,这是完全错误的,您必须开始学习fxml的工作原理,从示例开始。我已经提供了一个链接,通过它将给你一个更好的想法。
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.media.*?>
<?import javafx.scene.layout.AnchorPane?>


<AnchorPane fx:id="anchorPane" fitHeight="200.0" fitWidth="200.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="astrolabe.astrolabe_introController" >
    <MediaView fx:id="astrolabe_intro"/>
</AnchorPane>