递归调用null对象引用上的getSupportFragmentManager()

时间:2016-07-17 23:50:09

标签: android android-fragments recursion android-dialogfragment

该函数的第一次调用有效,但在关闭第一个对话框后尝试调用自身时,应用程序崩溃

Attempt to invoke virtual method 'android.support.v4.app.FragmentManager android.support.v4.app.FragmentActivity.getSupportFragmentManager()' on a null object reference

也许有人可以帮我找到我的错误?我的假设是,当第二个对话框试图打开时,对话框的第一个实例可能仍处于打开状态?

public void displayDialog(int id) {
    currImportId = id;
    BottomSheetDialogFragment bottomSheetDialogFragment = new MediaAddFragment();
    Bundle bundle = new Bundle();
    bundle.putInt("formtype", MediaAddFragment.FORMTYPE_IMPORT);
    bundle.putString("name", importStreams.get(id).getName());
    bundle.putString("url", importStreams.get(id).getUrl());
    bottomSheetDialogFragment.setArguments(bundle);
    bottomSheetDialogFragment.show(getActivity().getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
    getActivity().getSupportFragmentManager().executePendingTransactions();
    bottomSheetDialogFragment.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            onResume();
            displayDialog(currImportId + 1);
        }
    });
    dismiss();
}

亲切的问候,

Battlestr1k3

0 个答案:

没有答案