java.lang.IllegalStateException: YouTubeServiceEntity not initialized error when using YouTubePlayerApi <p>I'm using YouTubePlayerAPi and YouTubePlayerSupportFragment in my app and i'm getting this error reported, but i can't find out what is causing it. I've looking for information but there is no much about...</p> <p>In The stackstrace there is any line error pointing to any of my classes or activities... </p> <p>Any idea of it?</p> <pre><code>java.lang.IllegalStateException: YouTubeServiceEntity not initialized at android.os.Parcel.readException(Parcel.java:1433) at android.os.Parcel.readException(Parcel.java:1379) at com.google.android.youtube.player.internal.l$a$a.a(Unknown Source) at com.google.android.youtube.player.internal.o.a(Unknown Source) at com.google.android.youtube.player.internal.ad.a(Unknown Source) at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source) at com.google.android.youtube.player.YouTubePlayerView$1.a(Unknown Source) at com.google.android.youtube.player.internal.r.g(Unknown Source) at com.google.android.youtube.player.internal.r$c.a(Unknown Source) at com.google.android.youtube.player.internal.r$b.a(Unknown Source) at com.google.android.youtube.player.internal.r$a.handleMessage(Unknown Source) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Thanks!</p> <p><strong>EDIT</strong></p> <p>My custom YoutubePlayerFragment Class: YouTubeVideoPlayerFragment.java</p> <pre><code>public class YouTubeVideoPlayerFragment extends YouTubePlayerSupportFragment { private static final String ARG_URL = "url"; // =========================================================== // Constructors // =========================================================== /** * Mandatory empty constructor for the fragment manager to instantiate the * fragment (e.g. upon screen orientation changes). */ public YouTubeVideoPlayerFragment() { } /** * Factory method to generate a new instance of the fragment given a video URL. * * @param url The video url this fragment represents * @return A new instance of this fragment with itemId extras */ public static YouTubeVideoPlayerFragment newInstance(String url) { final YouTubeVideoPlayerFragment mFragment = new YouTubeVideoPlayerFragment(); // Set up extras final Bundle args = new Bundle(); args.putString(ARG_URL, url); mFragment.setArguments(args); // Initialize YouTubePlayer mFragment.init(); return mFragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } private void init(){ initialize(Constants.API_KEY, new YouTubePlayer.OnInitializedListener() { @Override public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) { if (!wasRestored) { youTubePlayer.cueVideo(getArguments().getString(ARG_URL)); youTubePlayer.setShowFullscreenButton(false); } } } </code></pre> <p>fragment.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout android:layout_height="match_parent" android:layout_width="match_parent" android:background="@color/black" &gt; &lt;!-- For YoutubeFragment --&gt; &lt;FrameLayout android:id="@+id/youtube_fragment" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>calling method:</p> <pre><code>// Create a new instance of YouTubeVideoPlayerFragment providing video id // and place it in the corresponding FrameLayout final YouTubeVideoPlayerFragment youTubeVideoPlayerFragment = YouTubeVideoPlayerFragment.newInstance(VIDEO_ID); final FragmentTransaction ft = getChildFragmentManager().beginTransaction(); ft.replace(R.id.youtube_fragment, youTubeVideoPlayerFragment); ft.commit(); </code></pre> <p><strong>EDIT</strong></p> <p>I've found out the origin of that error. This is the scenario: The Activity starts. In onCreate() instantiate a new YouTubeVideoPlayerFragment and initialize youTube object (which start the YouTubeServiceEntity internally) in its newInstance() method. Then the youtube fragment instantiated before, is attached with fragmentManager to the corresponding FrameLayout while video is loading. </p> <p><strong>Here is the issue:</strong> If user exits activity before video had been loaded, the exception is caused. </p> <p>So if the user want to exit activity in that case... What should i do and how?? i don't really know what to do!</p>