AlertDialog显示错误 Unable to add window token null is not for an application
来源:互联网 发布:手机淘宝怎么换主题 编辑:程序博客网 时间:2024/06/01 09:02
AlertDialog显示错误 Unable to add window token null is not for an application
在listView的onItemClick函数中显示一个AlertDialog,出现如下错误
Xml代码 1. 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解决。
原来代码中显示语句如下
Java代码
AlertDialog imageDialog = new AlertDialog.Builder(context).setTitle("状态操作").setItems(items, listener).create();
imageDialog.show();
其中context为在OnCreate中
Java代码 1. context = getApplicationContext();
得到
异常原因:AlertDialog创建语句
Java代码 public AlertDialog.Builder (Context context)
中,不能使用getApplicationContext()得到的context,而必须使用Activity,所以解决如下
解决方法:语句修改为
Java代码
AlertDialog imageDialog = new AlertDialog.Builder(Activity.this).setTitle("状态操作").setItems(items, listener).create();
imageDialog.show();
其中的Activity为当前Activity的名称
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开发
- Ibatis返回结果集
- 使用Maven管理进行多模块开发
- Oracle数据库中几种非常有用的函数(with……as等)
- android PathClassLoader couldn't find "libxxx.so"
- 事务四大属性ACID
- AlertDialog显示错误 Unable to add window token null is not for an application
- Linux_Chrome出现Adobe Flash Player is out of date解决方法
- Recyclerview添加头布局
- 简单学习Nginx之:动静分离
- [Android高级进阶] - Android View绘制流程
- Mybatis 批量插入带oracle序列例子+ORA-02287: 此处不允许序号
- 微信开发之准备阶段
- mybatis insert不成功问题
- 深度解析Gradle编译React native时遇到的那些坑【适用于Android开发者】