Join FlipAndroid.COM Telegram Group: https://t.me/joinchat/F_aqThGkhwcLzmI49vKAiw


Error al inflacionar la clase com.google.android.youtube.player.YouTubePlayerView

Tengo problemas para empezar con la API de Youtube de Android.
Tengo una ActionBarActivity que tiene una v4.ViewPager y quería poner múltiples YouTubePlayerSupportFragment dentro.
Tengo el Error inflating class com.google.android.youtube.player.YouTubePlayerView , mi sugerencia es que algo en la cadena de herencia está mal, pero no sé qué.

Mi código hasta ahora: XML:

 <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" > <com.google.android.youtube.player.YouTubePlayerView android:id="@+id/youtube_player" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#fff" android:padding="5dp" /> </FrameLayout> 

Java:

 public class MyYoutubeFragment extends YouTubePlayerSupportFragment { private static final String API_KEY = ""; private String videoId = "qNggvk8QtaY"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_youtube, container, false); YouTubePlayerView youTubePlayerView = (YouTubePlayerView) view.findViewById(R.id.youtube_player); youTubePlayerView.initialize(API_KEY, this); return view; } @Override public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult result) { Toast.makeText(getActivity(), "Failured to Initialize!", Toast.LENGTH_LONG).show(); } @Override public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) { player.setPlayerStateChangeListener(playerStateChangeListener); player.setPlaybackEventListener(playbackEventListener); if (!wasRestored) { player.cueVideo(videoId); } } 

}

LogCat:

 android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.youtube.player.YouTubePlayerView at android.view.LayoutInflater.createView(LayoutInflater.java:633) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at app.com.example.martinhatzung.movieapp.fragments.MyYoutubeFragment.onCreateView(MyYoutubeFragment.java:54) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489) at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486) at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) at android.support.v4.view.ViewPager.populate(ViewPager.java:1073) at android.support.v4.view.ViewPager.populate(ViewPager.java:919) at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441) at android.view.View.measure(View.java:17430) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463) at android.view.View.measure(View.java:17430) at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1260) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at android.widget.ScrollView.onMeasure(ScrollView.java:337) at android.view.View.measure(View.java:17430) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at android.view.View.measure(View.java:17430) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:453) at android.view.View.measure(View.java:17430) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at android.view.View.measure(View.java:17430) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) at android.view.View.measure(View.java:17430) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560) at android.view.View.measure(View.java:17430) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2001) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1166) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5786) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:550) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Nat 

One Solution collect form web for “Error al inflacionar la clase com.google.android.youtube.player.YouTubePlayerView”

Cambia tu clase así. También no se olvide de usar API_KEY real, en su código es sólo una cadena vacía

 public class MyYoutubeFragment extends YouTubePlayerSupportFragment { private static final String API_KEY = ""; private String videoId = "qNggvk8QtaY"; public static MyYoutubeFragment newInstance() { MyYoutubeFragment playerYouTubeFrag = new MyYoutubeFragment(); playerYouTubeFrag.initialize(API_KEY, this); return playerYouTubeFrag; } @Override public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult result) { Toast.makeText(getActivity(), "Failured to Initialize!", Toast.LENGTH_LONG).show(); } @Override public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) { player.setPlayerStateChangeListener(playerStateChangeListener); player.setPlaybackEventListener(playbackEventListener); if (!wasRestored) { player.cueVideo(videoId); } } } 

También carga esto como abajo

 fragmentManager.beginTransaction() .add(R.id.video_view, MyYoutubeFragment.newInstance()) .commit(); 
    FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.