AlertDialog显示错误 Unable to add window token null is not for an application
来源:互联网 发布:阿里云 cdn 编辑:程序博客网 时间:2024/06/01 10:40
在listView的onItemClick函数中显示一个AlertDialog,出现如下错误
- 08-07 21:26:43.506: ERROR/AndroidRuntime(9390): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
后google解决。
原来代码中显示语句如下
- AlertDialog imageDialog = new AlertDialog.Builder(context).setTitle("状态操作").setItems(items, listener).create();
- imageDialog.show();
其中context为在OnCreate中
- context = getApplicationContext();
得到
异常原因:AlertDialog创建语句
- public AlertDialog.Builder (Context context)
中,不能使用getApplicationContext()得到的context,而必须使用Activity,所以解决如下
解决方法:语句修改为
- AlertDialog imageDialog = new AlertDialog.Builder(Activity.this).setTitle("状态操作").setItems(items, listener).create();
- imageDialog.show();
其中的Activity为当前Activity的名称
参考:
http://blog.csdn.net/yimo29/article/details/6004782
0 0
- AlertDialog显示错误 Unable to add window token null is not for an application
- 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
- 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
- AlertDialog显示错误 Unable to add window token null is not for an application
- AlertDialog显示错误 Unable to add window token null is not for an application
- AlertDialog显示错误 Unable to add window token null is not for an application
- AlertDialog显示错误 Unable to add window token null is not for an application
- AlertDialog:Unable to add window -- token null is not for an application
- AlertDialog Unable to add window -- token null is not for an application
- 使用AlertDialog.Builder的时候出现错误:unable to add window --token null is not for an application的解决办法
- Unable to add window -- token null is not for an application错误的解决方法
- Android Custom Dialog错误Unable to add window -- token null is not for an application
- Android Custom Dialog错误Unable to add window -- token null is not for an application
- Android Custom Dialog错误Unable to add window -- token null is not for an application
- Unable to add window -- token null is not for an application错误的解决方法
- Unable to add window -- token null is not for an application错误的解决方法 android开发
- OLEDB和ODBC的区别
- struts2.xml配置文件的自动提示配置
- Android--多线程之Handler
- Integer to Roman
- (信息搜集)通过DNS和IP地址挖掘目标网络信息:whois
- AlertDialog显示错误 Unable to add window token null is not for an application
- 搭建一个 Maven 工程
- Java程序内存分析
- NSArray&NSMutableArray常用操作梳理
- Python 中读取csv文件中有中文的情况
- mark i++&++i
- 自定义Toast
- Jabber/XMPP中文翻译计划
- 欢迎使用CSDN-markdown编辑器