java.lang.illegalargumentexception android.support.v4.app.fragmentmanagerimpl.movetostate

时间:2019-07-03 07:53:58

标签: java android android-fragments fragment

我有一个放置在活动中的多个片段的代码库,涉及许多事务,例如替换和删除。我不太确定这个通用错误是由于哪个片段而崩溃的,如果对此问题有任何解决的办法,那就好了吗?

  

错误:

java.lang.IllegalArgumentException: 
  at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1413)
  at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManager.java:1740)
  at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1809)
  at android.support.v4.app.FragmentManagerImpl.dispatchStateChange (FragmentManager.java:3217)
  at android.support.v4.app.FragmentManagerImpl.dispatchReallyStop (FragmentManager.java:3198)
  at android.support.v4.app.FragmentController.dispatchReallyStop (FragmentController.java:240)
  at android.support.v4.app.FragmentActivity.onReallyStop (FragmentActivity.java:677)
  at android.support.v4.app.FragmentActivity.doReallyStop (FragmentActivity.java:656)
  at android.support.v4.app.FragmentActivity$1.handleMessage (FragmentActivity.java:87)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:206)
  at android.app.ActivityThread.main (ActivityThread.java:6784)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:240)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:852)

由于无法复制,因此无法测试或尝试。

MainActivity extends BaseActivity {

@Override
public void pushFragment(BaseFragment fragment) {

        if (isFinishing() || fragment == null) {
            return;
        }
        try {
            super.pushFragment(fragment);
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction transaction = fragmentManager.beginTransaction();
            if (fragment instanceof FragmentTestOne) {
                findViewById(R.id.content_test_one).setVisibility(View.VISIBLE);
                transaction.replace(R.id.content_channel_epg, fragment);
            } else if (fragment instanceof FragmentTestTwo) {
findViewById(R.id.content_test_two).setVisibility(View.VISIBLE);
                transaction.replace(R.id.content_test_two, fragment);
            } else {            
                transaction.add(R.id.content_test_three, fragment);
            }
            transaction.addToBackStack(null);
            transaction.commitAllowingStateLoss();
        } catch (Throwable e) {
            e.printStackTrace();
        }
}

}

BaseActivity extends AppCompatActivity{

pushFragment(BaseFragment fragment){
}

}

public FragmentTestOne extends BaseFragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_test_one, container, false);
        readBundleValues(getArguments());
return rootView;
   }
// Other part of implementation goes here...
}

public FragmentTestTwo extends BaseFragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_test_two, container, false);
        readBundleValues(getArguments());
return rootView;
   }
// Other part of implementation goes here...
}

public BaseFragment extends Fragment{
}

期望从我的代码中获得至少可重现的方案。或修复将不胜感激。 谢谢您的提前帮助。

0 个答案:

没有答案