片段方法時,我有一個通過調用其他片段的fragmentactivity:NullPointerException異常調用從活動
FragmentView1 f = (FragmentView1) this.getSupportFragmentManager()
.findFragmentByTag(getFragmentTag(0));
和我getFragmentTag()函數是:
private String getFragmentTag(int pos){
return "android:switcher:"+R.id.viewpager+":"+pos; //fragmentpageradapter auto generated tag
}
不是問題是每當我調用F .somemethod,我得到一個nullpointerexception。
我試着用
Log.w("HELLO1",""+ f.getTag());
它返回NullPointerException異常。
我的猜測是你的'getFragmentTag(0)'沒有返回你所期待的 – BlackHatSamurai
不,它返回正確的標籤。我在我的FragmentView1中調用了'getTag()',在我的fragmentActivity中調用了'getFragmentTag(0)',並且都返回了相同的結果 – user1304