无法将androidx.fragment.app.fragment强制转换为com.google.android.you



我在片段中使用YoutubePlayerView,但当我从片段中获得YoutubePlayerView的引用时,我会得到不可转换类型的错误。有人能告诉我我做错了什么吗?

这是我的layout.xml文件:

<fragment
android:id="@+id/youtube_frag"
android:name="com.google.android.youtube.player.YouTubePlayerFragment"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
/>

Fragment.class:

myouTubePlayerView= (YouTubePlayerFragment)getFragmentManager().findFragmentById(R.id.youtube_frag);

在这一行中,我得到了一个错误,无法将片段投射到youtubeplayerfragment中。请帮帮我。

查看此链接Youtube播放器支持片段不再适用于Android studio 3.2(androidx(

相关内容

最新更新