Unable to add window -- token null is not for an application
来源:互联网 发布:网络黑白哪里买 编辑:程序博客网 时间:2024/06/05 05:35
代码中出现如下错误:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
分析:
问题在于new AlertDialog.Builder(Context),虽然这里的参数是AlertDialog.Builder(Context context)
但我们不能使用getApplicationContext()获得的Context,而必须使用Activity的Context对象,因为只有一个Activity才能添加一个窗体。
解决方法:
将new AlertDialog.Builder(Context context)中的参数用Activity的Context对象即可
弹出确认框
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.confirm_title).setMessage(R.string.confirm_content).setPositiveButton(R.string.confirm_ok, new OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int arg1) {dialogInterface.dismiss();masterClear(getApplicationContext());}}).setNegativeButton(R.string.confirm_cancel, new OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int arg1) {dialogInterface.cancel();}}).show();
0 0
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
- WindowManager$BadTokenException: 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
- Unable to add window -- token null is not for an application 的解决办法
- Unable to add window -- token null is not for an application
- AlertDialog: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
- Unable to add window -- token null is not for an application
- AlertDialog显示错误 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:
- 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
- 花生壳动态域名绑定步骤及相关问题
- android ListView美化-->几个比较特别的属性
- adb server is out of date. killing...
- Android恢复出厂设置
- Android预安装软件&adb命令&编译源码
- Unable to add window -- token null is not for an application
- Android查看系统信息
- Android网络连接相关广播
- Android设置默认Launcher
- Android切换系统语言,自动更新应用界面显示语言
- Android应用升级,检测更新,下载,检验,安装
- 聚类分析应用之市场细分
- 找资源之路
- Android获取Ethernet、WIFI的ip和mac地址