首页 Android android AlertDialog显示错误 Unable to add window token null is not for an application解决办法

android AlertDialog显示错误 Unable to add window token null is not for an application解决办法

作者:胡同里的砖头 围观群众:1159 更新于:2017-03-24

报错:Unable to add window token null is not for an application

  

异常原因:AlertDialog创建语句public AlertDialog.Builder (Context context)中,不能使用getApplicationContext()得到的context,而必须使用Activity,所以解决如下

 

解决办法:

将 new AlertDialog.Builder(getApplicationContext()) 改为 new AlertDialog.Builder(MainActivity.this)

其中MainActivity 为当前Activity的名称

  • 本文标题: android AlertDialog显示错误 Unable to add window token null is not for an application解决办法
  • 文章分类:【Android】
  • 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
留言评论
站点声明:
1、本站【胡同里的砖头】个人博客,借鉴网上一些博客模板,取其各优点模块自行拼装开发,本博客开发纯属个人爱好。
2、所有笔记提供给广大用户交流使用,可转载,可复制,纯个人开发所遇问题锦集记录使用
Copyright © huzlblog.com All Rights Reserved. 备案号:苏ICP备2021056683号-8