AlertDialog显示错误 Unable to add window token null is not for an application


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的名称
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值