Skip to content Skip to sidebar Skip to footer

Fatal Exception: Java.lang.noclassdeffounderror: Rt

Fatal Exception: java.lang.NoClassDefFoundError: rt at rs.(SourceFile:17) at android.support.v7.widget.RecyclerView.onSaveInstanceState(SourceFile:201) at android.view.Vie

Solution 1:

I fix this by release YouTubePlayer at onSavedInstanceState and onStop.

@NullableprotectedYouTubePlayer mUtPlayer;

@OverridepublicvoidonSaveInstanceState(Bundle outState) {
    /* release ut when home button pressed. */if (mUtPlayer != null) {
        mUtPlayer.release();
    }
    mUtPlayer = null;
    super.onSaveInstanceState(outState);
}

@OverridepublicvoidonStop() {
    /* release ut when go to other fragment or back pressed */if (mUtPlayer != null) {
        mUtPlayer.release();
    }
    mUtPlayer = null;
    super.onStop();
}

Solution 2:

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.

@OverrideprotectedvoidonResume() {
        super.onResume();
        YouTubePlayerFragment youTubePlayerFragment =
                (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtubeFragmentView);
        youTubePlayerFragment.initialize(YouTubeDeveloperKey, this);
    }

    @OverrideprotectedvoidonPause() {
        super.onPause();
        if (youTubePlayer != null) {
            youTubePlayer.release();
        }
        youTubePlayer = null;
    }

Solution 3:

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:

publicinterface ICallableOnView {
    voidcall(View view);
}

publicstaticvoidrecursiveCallOnView(View view, ICallableOnView callableOnView) {
    if (view != null) {
        if (view instanceofViewGroup) {
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                recursiveCallOnView(((ViewGroup) view).getChildAt(i), callableOnView);
            }
        }
        callableOnView.call(view);
    }
}

@OverridepublicvoidonSaveInstanceState(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, newICallableOnView() {
        @Overridepublicvoidcall(View view) {
            view.setSaveEnabled(false);
        }
    });

    super.onSaveInstanceState(outState);
}

Hope this helps somebody, blessings to all.

Post a Comment for "Fatal Exception: Java.lang.noclassdeffounderror: Rt"