我正在尝试使用适用于Android的新版YouTube播放器API实现布局.目前,我有一个简单的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerFragment"
android:id="@+id/youtube_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="Nothin"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在,在我的活动中,我有以下内容:
public class MainActivity extends FragmentActivity implements YouTubePlayer.OnInitializedListener
Run Code Online (Sandbox Code Playgroud)
我的印象是在我的布局中使用片段意味着我需要使用FragmentActivity(来自android.support.v4.app.FragmentActivity).但是,当我运行此命令时,我收到以下异常:
java.lang.ClassCastException: com.google.android.youtube.player.YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment
Run Code Online (Sandbox Code Playgroud)
这在扩展Activity而不是FragmentActivity时有效.我怎样才能解决这个问题?