致命异常:java.lang.NoClassDefFoundError:rt

时间:2017-06-15 03:44:48

标签: android

import { Subpart} from './subpart.model.ts';

let jsonSubpart: Subpart = {
      "val-type": userInput.valtype,
      "val-name": userInput.valname,
      "op-ter": userInput.opter,
      "value": userInput.val,
      "match-twice": false,
      "case-sensitive": false
    }

3 个答案:

答案 0 :(得分: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();
}

答案 1 :(得分:3)

对于Razgriz解决方案不起作用的人,只需在onPause而不是onSaveInstanceStateonStop中添加相同的行,并初始化YouTubePlayerFragment in onResume而不是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;
    }

答案 2 :(得分: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);
}

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