2017-06-15 121 views
10
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) 
+0

粘贴你的代码发生错误 –

+0

你的应用程序在棉花糖或更高版本中工作 –

+0

我不知道它在哪里发生。只需在织物crashlytics中获取此崩溃日志。 –

回答

8

我通过在onSavedInstanceState和onStop上发布YouTubePlayer来解决此问题。

@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(); 
} 
+0

此解决方案正在为我工​​作,谢谢! – NehaK

+0

这个解决方案就像一个魅力,谢谢! –

+0

不适合我。请提出其他解决方案。 –

3

对于人们Razgriz的解决方案不起作用,只是添加同一线而不是onSaveInstanceStateonStop,并在onResume初始化YouTubePlayerFragment,而不是在onCreate因此这将是每一个可用时间活动在前台,并在应用程序转到后台时发布:

请注意,代码应始终放在super方法之后。

@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; 
    } 
+0

此修复程序会导致玩家在每次应用程序从所有设备上的onPause()返回时都抛出内部错误(我甚至没有收到此问题)。 @Razgriz Bill Wong的解决方案也是如此。 – Abbas

0

以防万一上面给出的解决方案不适合你,考虑下一个,它的工作原理!这里的诀窍是避免保存与YouTube相关的所有视图的状态。当然该解决方案有它的缺点,但它比应用程序崩溃就像我的事更好:

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); 
} 

希望这有助于别人,祝福所有。