Android Dialog显示错误 Unable to add

作者: 唠嗑008 | 来源:发表于2017-06-22 22:47 被阅读87次

弹出一个自定义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

    本文链接:https://www.haomeiwen.com/subject/gdlqcxtx.html