android片段管理器中的Nullpointerexception

时间:2014-03-03 04:41:47

标签: android android-fragments nullpointerexception

我有一个代码来重新创建地图,例如:

public void onDestroyView() {
        super.onDestroyView();    

        if (this.f != null
                && getFragmentManager().findFragmentById(
                        this.f.getId()) != null) {
             Log.i("DESTROY VIEW MAP", "MAP!!!!!!!!!!!"+f);
             myFragmentManagerSupport.beginTransaction().remove(this.f).commit();
             Log.i("DESTROY VIEW MAP 222222222222222", "MAP!!!!!!!!!!!"+f);
           // this.f = null;
            Log.i("DESTROY VIEW MAP 333333333333333333", "MAP!!!!!!!!!!!"+f);
        }

    }

但是当我从这一部分回来时,我正在关闭力量。我的代码中有错误

myFragmentManagerSupport.beginTransaction().remove(this.f).commit();

当我评论代码时,没有问题。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

使用相同的fragmentManager对象 public void onDestroyView(){         super.onDestroyView();

    if (this.f != null
            && myFragmentManagerSupport().findFragmentById(
                    this.f.getId()) != null) {
         Log.i("DESTROY VIEW MAP", "MAP!!!!!!!!!!!"+f);
         myFragmentManagerSupport.beginTransaction().remove(this.f).commit();
         Log.i("DESTROY VIEW MAP 222222222222222", "MAP!!!!!!!!!!!"+f);
       // this.f = null;
        Log.i("DESTROY VIEW MAP 333333333333333333", "MAP!!!!!!!!!!!"+f);
    }

}