Unable to add window -- token null is not for an application

来源:互联网 发布:淘宝商品色差严重 编辑:程序博客网 时间:2024/04/27 23:50

android.view.WindowManager$BadTokenException:Unable to add window -- token null is not for anapplication

分析:

问题在于newAlertDialog.Builder(Context),虽然这里的参数是AlertDialog.Builder(Contextcontext)

但我们不能使用getApplicationContext()获得的Context,而必须使用Activity的Context对象,因为只有一个Activity才能添加一个窗体。  

解决方法:

将new AlertDialog.Builder(Contextcontext)中的参数用Activity的Context对象即可.

0 0
原创粉丝点击