代码中的java.lang.IllegalStateException

时间:2017-10-03 13:11:41

标签: android android-fragments fragment handler

这是我在异步任务的postexecute中的代码,它给非法状态异常我试过每个解决方案但没有得到任何帮助我

new Handler().post(new Runnable() {
    @Override
    public void run() {
        Fragment fragment = newFragmentNoOffer();
        FragmentManager fragmentManager =getActivity().getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.content_frame, fragment);
        fragmentTransaction.addToBackStack(null);
        if (getActivity() != null) {
            fragmentTransaction.commit();
        } else {
            fragmentTransaction.commitAllowingStateLoss();
        }
    }
});
  

java.lang.IllegalStateException:        在android.app.FragmentManagerImpl.checkStateLoss       (FragmentManagerImpl.java:1411)         在android.app.FragmentManagerImpl.enqueueAction       (FragmentManagerImpl.java:1429)         在android.app.BackStackRecord.commitInternal       (BackStackRecord.java:687)        在android.app.BackStackRecord.commit(BackStackRecord.java:663)        在com.waypedia.activity.FragmentAppList $ 3 $ 1.run        (FragmentAppList.java)        在android.os.Handler.handleCallback(Handler.java:739)         在android.os.Handler.dispatchMessage(Handler.java:95)         在android.os.Looper.loop(Looper.java:224)         在android.app.ActivityThread.main(ActivityThread.java:5526)         在java.lang.reflect.Method.invoke(Method.java)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run         (ZygoteInit.java:726)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

这显示了蜂窝上方设备的错误

0 个答案:

没有答案