Android Dialog显示错误 Unable to add window token null is not for an application

弹出一个自定义Dialog,出现如下错误

08-07 21:26:43.506: ERROR/AndroidRuntime(9390): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
LoadingDialog dialog = new LoadingDialog(context); 

其中context为Fragment中

context = getApplicationContext();  

异常原因:Dialog创建语句中,不能使用getApplicationContext()得到的context,而必须使用Activity的context,如果在fragment中,就是context=getActivity();

你可能感兴趣的:(Android Dialog显示错误 Unable to add window token null is not for an application)