java.lang.IllegalStateException:从片段调用方法时

时间:2012-01-21 06:30:07

标签: android android-fragments

如何摆脱这个, 我正在为Fragments使用Google兼容性库。我在log cat中有以下错误。 MainMenuScreen是FragmentActivity的地方。

java.lang.IllegalStateException: Activity has been destroyed
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1314)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525)

我试图从fragmentActivity中的片段调用一个方法,如下面的

MainMenuScreen objMain= new MainMenuScreen();
                    if(SharedVariables.isTablet){

                        objMain.showFragment();}else{....}

在MainMenuScreen中,方法是

public void showTrafficCasesDetails(){          
        detailsFragmentRoot.setVisibility(View.VISIBLE);            
        DetailsFrag detailsFrag=new DetailsFrag ();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();       
        transaction.replace(R.id.mainScreenDetailsFrame, detailsFrag);
        transaction.commit();
    }

1 个答案:

答案 0 :(得分:1)

解决了......

MainMenuScreen objMain=(MainMenuScreen)getActivity(); if(SharedVariables.isTablet){

                        objMain.showFragment();}