I am trying to implement a layout using the new YouTube Player API for Android . Currently, I 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 activity, I have the following:
public class MainActivity extends FragmentActivity implements YouTubePlayer.OnInitializedListener
I was under the impression that using a fragment in my layout, meant that I needed to use a FragmentActivity (which is from android.support.v4.app.FragmentActivity). However, I am getting 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 Activity instead of FragmentActivity. How can I fix this?
YouTubePlayerFragment inherits from android.app.Fragment, and you cast it somewhere to android.support.v4.app.Fragment. If you want to use this class on older API-s then use YouTubePlayerSupportFragment, otherwise fix your imports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With