Unable to add window -- token null is not for an application
来源:互联网 发布:苹果电脑网络恢复系统 编辑:程序博客网 时间:2024/06/06 06:45
在创建一个Dialog时,发生的错误:
Unable to add window -- token null is not for an application
AlertDialog.Builder builder; AlertDialog alertDialog; Context mContext = getApplicationContext(); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_dialog, (ViewGroup)findViewById(R.id.layout_root)); TextView text = (TextView) layout.findViewById(R.id.text); text.setText("Hello, this is a custom dialog!"); ImageView image = (ImageView) layout.findViewById(R.id.image); image.setImageResource(R.drawable.icon); builder = new AlertDialog.Builder(mContext); builder.setView(layout); alertDialog = builder.create(); alertDialog.show();
查询SDK帮助文档:
Return the context of the single, global Application object of the current process. This generally should only be used if you need a Context whose lifecycle is separate from the current context, that is tied to the lifetime of the process rather than the current component.
把这句Context mContext = getApplicationContext();
改成Activity.this即可
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
- php 图片式报表 我百度云盘有资料
- Spring整合quartz
- linux内核设计与实现 第三章笔记
- This function or variable may be unsafe
- .lib .dll 两种库文件
- Unable to add window -- token null is not for an application
- View Pager Indicator_1
- 设计模式之装饰者模式
- NYOJ73 比大小
- hive 处理小文件,减少map数
- xfire開發webservice所需jar包
- Windows平台安装Beautiful Soup
- 【自动构建系列】自动部署环境的shell脚本
- 根据上次输入操作的时间设置离开状态