I am trying to implement a layout using the new YouTube Player API for Android . I currently have a simple layout:
<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>
Now, in my work, I have the following:
public class MainActivity extends FragmentActivity implements YouTubePlayer.OnInitializedListener
I got the impression that using the fragment in my layout meant that I needed to use FragmentActivity (from android.support.v4.app.FragmentActivity). However, I get the following exception when I run this:
java.lang.ClassCastException: com.google.android.youtube.player.YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment
This works when I extend an Activity instead of a FragmentActivity. How can i fix this?
source share