Skip to content Skip to sidebar Skip to footer

Nullpointerexception On Super.onstart()

Currently I'm writing Fragment that extends custom SherlockFragment that extends YouTubePlayerSupportFragment. Unfortunately, app crashes. CODE: public static class YouTubeVid

Solution 1:

It's not clear in the SDK but as far as I was able to work it out, you don't extend YouTubePlayerFragment. You simply include the fragment in your layout (it works as a nested fragment too).

Basically you have two alternatives:

  • extend YouTubeBaseActivity and inflate a layout which includes a YouTubePlayerView - it works but you can't use Fragments

  • Use your favourite Activity and inflate a layout which includes the YouTubePlayerFragment. Do not extend it.

I have successfully added the YoutubePlayerFragment as a nested fragment too (update: this causes some memory leaks so you might prefer to avoid it). You can add other components around the YouTubePlayerFragment but be careful as the docs say you can't overlay this view with other view while the video is playing.

So, to solve your problem don't extend YouTubePlayerFragment, simply include it in your layout. By calling initialize on this fragment you will get a YouTubePlayer in the callback which you can use to control the video.

Solution 2:

Faced the same problem and searched stackoverflow many times. Solution was just Simply extend Fragment instead of YouTubePlayerSupportFragment.

publicclassFragmentTrailersextendsFragmentimplementsYouTubePlayer.OnInitializedListener {
publicstaticfinalStringDEVELOPER_KEY= BuildConfig.YOUTUBE_API;
privatestaticfinalintRECOVERY_DIALOG_REQUEST=1;
private String url;

YouTubePlayerSupportFragment youTubePlayerView;

@Nullable@Overridepublic View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Viewview= inflater.inflate(R.layout.detail_fragment_trailers, container, false);

    youTubePlayerView = YouTubePlayerSupportFragment.newInstance();
    FragmentTransactiontransaction= getChildFragmentManager().beginTransaction();
    transaction.add(R.id.youtube_fragment, youTubePlayerView).commit();

    youTubePlayerView.initialize(DEVELOPER_KEY, this);

    return view;
}
}

XML Layout file.

  <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/youtube_fragment"/>

Post a Comment for "Nullpointerexception On Super.onstart()"