NullPointerException calling activity using DialogFragment

前端 未结 2 1181
孤独总比滥情好
孤独总比滥情好 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:45

    Use :

    getActivity().getApplicationContext()
    

    Instead of:

    getActivity()
    

    EDIT:

    Use this method

    @Override
    public void onAttach(SupportActivity activity) {
        super.onAttach(activity);
    }
    

提交回复
热议问题