Wie füge ich den YouTube-Player in mein SupportFragment ein?

Mein XML-Code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    style="@style/Container.MainBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
        android:layout_alignParentTop="true"
        android:id="@+id/youtube_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</RelativeLayout>

Code in Fragment

public class VideoFragment extends YouTubePlayerSupportFragment implements YouTubePlayer.OnInitializedListener {

    static private final String DEVELOPER_KEY = "MyKey";
    static private final String VIDEO = "ToMpzhdUD1Q";
    static private final String VIDEO1 = "K77avo920Jc";
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View videoView = inflater.inflate(R.layout.video_fragment, container, false);
        getActivity().setTitle("Youtube");

        YouTubePlayerSupportFragment youTubePlayerSupportFragment = new YouTubePlayerSupportFragment();
        youTubePlayerSupportFragment.initialize(DEVELOPER_KEY, this);

        return videoView;
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {

        List<String> list = new ArrayList<>();
        list.add(VIDEO);
        list.add(VIDEO1);
        youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
        youTubePlayer.cueVideos(list);

    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {

        Toast.makeText(getContext(), "FAIL!" + youTubeInitializationResult.toString(), Toast.LENGTH_LONG)
                .show();

    }
}

In Haupttätigkeit:

getSupportFragmentManager().beginTransaction().replace(R.id.main_container,fragment).addToBackStack(null).commit();

Error, wenn ich versuche, mein Fragment in Drawer zu öffnen:

java.lang.NullPointerException: Versuch, die virtuelle Methode 'void com.google.android.youtube.player.YouTubePlayerView.a ()' für eine Nullobjektreferenz unter com.google.android.youtube.player.YouTubePlayerSupportFragment.onStart (aufzurufen. Unbekannte Quelle

Antworten auf die Frage(2)

Ihre Antwort auf die Frage