Thursday, May 2, 2013

[android help] DialogFragment.dismiss crashing with NullPointerException


This may also occur when you call dismiss() before you have called show() like Sogger said.


After Dialog object is constructed but before dialog is not showed, if (mDialog != null) can be passed and NullPointerException will occur.


When you check if mDialog is null or not,



if (mDialog != null) {
mDialog.dismiss();
mDialog = null;
}


Add more conditions like below,



if ((mDialog != null) && mDialog.isAdded() && mDialog.isResumed()) {
mDialog.dismiss();
mDialog = null;
}


I think that mDialog.isAdded() condition might be enough...



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...