Error inflating class com.google.android.youtube.player.YouTubePlayerView In List Adapter

你。 提交于 2019-11-27 15:32:20

From the documentation:

Using this View directly is an alternative to using the YouTubePlayerFragment. If you choose to use this view directly, your activity needs to extend YouTubeBaseActivity.

Therefore, you must make sure your activity extends YouTubeBaseActivity. Alternatively, if your activity does not need to extend an activity provided by the library, you can use the YouTubePlayerSupportFragment and FrameActivity from android.support.v4.

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

In addition to not_a_bot's answer, I'd like to add that you should make sure that you call super.onCreate(Bundle) method, as it seems that YouTubeBaseActivity class doesn't have the @CallSuper annotation.

If you do not want to use fragment in your layout, another solution that you can use is extends your activity from YouTubeBaseActivity() . This will allow you use <com.google.android.youtube.player.YouTubePlayerView/> inside your layout

Example:

class PlayVideoActivity : YouTubeBaseActivity(), YouTubePlayer.OnInitializedListener {...}
user7156149

In your java file MainActivity.java try to replace public class MainActivity extends AppCompatActivity with public class MainActivity extends YouTubeBaseActivity.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!