2

I am getting this error

"Cannot access 'android.support.v4.app.Fragment' which is a supertype of 'com.google.android.youtube.player.YouTubePlayerSupportFragment'. Check your module classpath for missing or conflicting dependencies"

but I implemented all things correctly regarding youtube player API

private fun initializeYoutubePlayer() {
    
            youTubePlayerFragment = supportFragmentManager
                .findFragmentById(R.id.youtube_player_fragment) as YouTubePlayerSupportFragment
    
            if (youTubePlayerFragment === null)
                return;
    
            youTubePlayerFragment!!.initialize(
                Constants.DEVELOPER_KEY,
                object : YouTubePlayer.OnInitializedListener {
    
                    override fun onInitializationSuccess(
                        provider: YouTubePlayer.Provider, player: YouTubePlayer,
                        wasRestored: Boolean
                    ) {
                        if (!wasRestored) {
                            youTubePlayer = player
    
                            //set the player style default
                            youTubePlayer!!.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT)
    
    //                        youTubePlayer!!.cueVideo("lwg-k9_PAdM")
    
                            //cue the 1st video by default
                            youTubePlayer!!.cueVideo(youtubeVideoArrayList?.get(0)?.videoID)
                        }
                    }
    
                    override fun onInitializationFailure(
                        arg0: YouTubePlayer.Provider,
                        arg1: YouTubeInitializationResult
                    ) {
    
                        //print or show error if initialization failed
                        Log.e(TAG, "Youtube Player View initialization failed")
                    }
                })
        }
大陸北方網友
  • 3,696
  • 3
  • 12
  • 37
  • Check [this answer](https://stackoverflow.com/a/49767726/4092887) or, if you haven't done yet, search in Google `Cannot access 'android.support.v4.app.Fragment' which is a supertype` - that's how I got the linked answer. Hope it helps. – Mauricio Arias Olave Sep 18 '20 at 18:39
  • Did you ever figure out the solution? – Android Dev May 02 '22 at 20:20

0 Answers0