Reputation: 109
Fatal Exception: java.lang.NoClassDefFoundError: rt
at rs.(SourceFile:17)
at android.support.v7.widget.RecyclerView.onSaveInstanceState(SourceFile:201)
at android.view.View.dispatchSaveInstanceState(View.java:13651)
at android.view.ViewGroup.dispatchFreezeSelfOnly(ViewGroup.java:2835)
at android.support.v7.widget.RecyclerView.dispatchSaveInstanceState(SourceFile:220)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2821)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2821)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2821)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2821)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2821)
at android.view.View.saveHierarchyState(View.java:13634)
at android.support.v4.app.FragmentManagerImpl.saveFragmentViewState(FragmentManager.java:2594)
at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:2615)
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:2678)
at android.support.v4.app.FragmentController.saveAllState(FragmentController.java:134)
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:571)
at android.support.v7.app.AppCompatActivity.onSaveInstanceState(AppCompatActivity.java:509)
at android.app.Activity.performSaveInstanceState(Activity.java:1229)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1229)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3390)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3449)
at android.app.ActivityThread.access$1200(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(NativeStart.java)
Upvotes: 10
Views: 1764
Reputation: 2873
For the people that the solution of Razgriz does not work, just add the same lines in onPause
instead of in onSaveInstanceState
and onStop
, and initialize the YouTubePlayerFragment
in onResume
instead of in onCreate
so it'll be available every time the activity is in foreground and released when the app goes to the background:
Note that the code should always be placed after the super
methods.
@Override
protected void onResume() {
super.onResume();
YouTubePlayerFragment youTubePlayerFragment =
(YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtubeFragmentView);
youTubePlayerFragment.initialize(YouTubeDeveloperKey, this);
}
@Override
protected void onPause() {
super.onPause();
if (youTubePlayer != null) {
youTubePlayer.release();
}
youTubePlayer = null;
}
Upvotes: 3
Reputation: 1
Just in case the given solution above didn't work for you, consider the next one, it works! The trick here is to avoid saving the state of all views related to YouTube. Surely the solution has its drawbacks, but it is better than the app crashing like happened with mine:
public interface ICallableOnView {
void call(View view);
}
public static void recursiveCallOnView(View view, ICallableOnView callableOnView) {
if (view != null) {
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
recursiveCallOnView(((ViewGroup) view).getChildAt(i), callableOnView);
}
}
callableOnView.call(view);
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
// Disable view state saving to prevent saving states from youtube apk which cannot be restored.
// This is to avoid the bug "java.lang.NoClassDefFoundError: rt at rs.<clinit>(SourceFile:17)"
recursiveCallOnView(mViewHolder.youTubeVideoContainerLayout, new ICallableOnView() {
@Override
public void call(View view) {
view.setSaveEnabled(false);
}
});
super.onSaveInstanceState(outState);
}
Hope this helps somebody, blessings to all.
Upvotes: 0
Reputation: 81
I fix this by release YouTubePlayer at onSavedInstanceState and onStop.
@Nullable
protected YouTubePlayer mUtPlayer;
@Override
public void onSaveInstanceState(Bundle outState) {
/* release ut when home button pressed. */
if (mUtPlayer != null) {
mUtPlayer.release();
}
mUtPlayer = null;
super.onSaveInstanceState(outState);
}
@Override
public void onStop() {
/* release ut when go to other fragment or back pressed */
if (mUtPlayer != null) {
mUtPlayer.release();
}
mUtPlayer = null;
super.onStop();
}
Upvotes: 8