NullPointerException calling activity using DialogFragment

前端 未结 2 1216
孤独总比滥情好
孤独总比滥情好 2021-01-16 16:55

I am in the process of converting my dialogs to DialogFragments. I\'m following the instructions here but it looks like they are using it in an Activity<

2条回答
  •  梦谈多话
    2021-01-16 17:30

    Shouldn't you use getSupportFragmentManager() and add (.add(fragment, tag)) the new instance of your fragment to the FragmentTransaction by doing .beginTransaction() and then call commit()? I guess thats what you are trying to do.

    getActivity() returns null since your new Fragment instance is not attached to the Activity (native FragmentActivity/Activity or SherlockFragmentActivity/SherlockActivity, whatever it is).

    Do some readings about using fragments. Instantiantion of the fragment is not enough. Find about underlying operations after instantiation.

提交回复
热议问题