I am developing android card game, and i am using DialogFragment where I render some images and tell the player to take action against opponent.
the following piece of code gets executed many times with no errors at all but after lets say 5 to 10 times the following exception occurred.
E/AndroidRuntime: FATAL EXCEPTION: mainProcess: com.arabdealgame.arabdealgame, PID: 8359
                                                                             java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Dialog.setOwnerActivity(android.app.Activity)' on a null object reference
                                                                                 at android.app.DialogFragment.onActivityCreated(DialogFragment.java:482)
                                                                                 at com.arabdealgame.activities.dialog.RentCardDialog.onActivityCreated(RentCardDialog.java:342)
                                                                                 at android.app.Fragment.performActivityCreated(Fragment.java:2362)
                                                                                 at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1014)
                                                                                 at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
                                                                                 at android.app.BackStackRecord.run(BackStackRecord.java:815)
                                                                                 at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
                                                                                 at android.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:563)
                                                                                 at com.arabdealgame.bo.Actions.RentActionCard$5.run(RentActionCard.java:315)
                                                                                 at android.os.Handler.handleCallback(Handler.java:751)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                 at android.os.Looper.loop(Looper.java:154)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
the above exception is telling that inside android.app.DialogFragment mDialog is null at the line mDialog.setContentView(view);
android.app.DialogFragment
 public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (!mShowsDialog) {
            return;
        }
        View view = getView();
        if (view != null) {
            if (view.getParent() != null) {
                throw new IllegalStateException("DialogFragment can not be attached to a container view");
            }
            mDialog.setContentView(view);
        }
        mDialog.setOwnerActivity(getActivity());
I am instantiating the dialog from here the error occur at
boolean executePendingTransactions = fm.executePendingTransactions(); which I added as suggested in a related post in order to fix the problem. before adding this statement the error occur without stating any class under my package
RentActionCard.java
 getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                MyLog.i(TAG, "run: --------------------------1");
                FragmentManager fm = getActivity().getFragmentManager();
                MyLog.i(TAG, "run: --------------------------2");
                RentCardDialog rentCardDialog = new RentCardDialog();
                MyLog.i(TAG, "run: --------------------------3");
                if (!GameInfo.getCurrentPlayer().isUser()) {
                    MyLog.i(TAG, "run: --------------------------4");
                    rentCardDialog.setAgainstUser(true);
                }
                rentCardDialog.show(fm, "ccc");
                boolean executePendingTransactions = fm.executePendingTransactions();
                MyLog.d(TAG, "RentActionCard - executePendingTransactions : " + executePendingTransactions);
                MyLog.i(TAG, "run: --------------------------5");
            }
        });
this method has been overridden for debugging purposes inside my dialog
@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        MyLog.i(TAG, "onActivityCreated: ----------------------------------");
        super.onActivityCreated(savedInstanceState);
    }
