android.view.WindowManager$BadTokenException: Unable to add window — token null
错误产生:
private Context mcontext;
@Override
protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext();
System.out.println("mcontext=" + mcontext);
}
- private Context mcontext;
- @Override
- protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext();
- System.out.println("mcontext=" + mcontext);
- }
private Context mcontext;
@Override
protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext();
System.out.println("mcontext=" + mcontext);
}
导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApplicationContext()获得的Context,而必须使用Activity,因为只有一个Activity才能添加一个窗体。
new AlertDialog.Builder(MyActivity.this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Warnning")
.setMessage(
"You forget to write the message. Do you want to fill out it ??")
.setPositiveButton("Yes", positiveListener).setNegativeButton(
"No", negativeListener).create().show();
android.view.WindowManager$BadTokenException: Unable to add window — token null相关推荐
- Android --- 刚刚进入 Activity 页面的时候无法打开对话框,报错 Unable to add window -- token null is not valid; is your
报错如下: E/AndroidRuntime: FATAL EXCEPTION: mainProcess: com.gxuwz.yixin, PID: 29723java.lang.RuntimeEx ...
- AlertDialog显示错误 Unable to add window token null is not for an application
在listView的onItemClick函数中显示一个AlertDialog,出现如下错误 08-07 21:26:43.506: ERROR/AndroidRuntime(9390): andro ...
- Android之运行PopupWindow提示Unable to add window -- token null is not valid; is your activity running?
1.问题 在使用PopupWindow的时候,我们构建好了直接放在Activity的onCreate函数里面直接运行,提示这个错误 Unable to add window -- token null ...
- Android之Dialog提示Unable to add window -- token is not valid; is your activity running?
1.问题 Dialog奔溃提示Unable to add window -- token android.os.BinderProxy@b251dbc is not valid; is your ac ...
- android Unable to add window -- token null is n...
2019独角兽企业重金招聘Python工程师标准>>> 问题的原因:调用了getApplicationContext()复制给你的context 解决方法:将activity赋值co ...
- Unable to add window token null is not valid is your activity running
莫名其妙的报错 错误原因是不在主线程调用了弹窗方法 解决方法很简单 创建Handler static final int REFRESH_COMPLETE = 0X1112; private Hand ...
- 自定义对话框 提示:Unable to add window token null is not for an application
这是因为在new Dialog(context);的时候传入的context是通过getApplicationContext()获得的,这样就会报错. 把context的获得方式改为MainActiv ...
- AlertDialog Unable to add window token null is
2019独角兽企业重金招聘Python工程师标准>>> AlertDialog.Builder参数应该是Activity而不是getApplicationContext(); 转载于 ...
- Unable to add window -- token null is not for an application
导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApp ...
最新文章
- 中科院等发布《2017研究前沿》 中国25个前沿表现卓越 居全球第二
- 【090】Excel VBA 基础
- android杀死进程
- 有了内阻值,怎么判断电池是否健康?
- 【LeetCode】TreeNode类实现解析(java实现)
- u盘pe无人值守linux,从U盘无人值守安装linux操作系统(纯实践笔记
- Android 沉浸式状态栏完美解决方案
- python 关于main函数以及if __name__=='__main__'的理解
- 一直弹出adb已停止工作(远程主机强迫关闭现有的连接)的最简单完美解决法
- 亲测有效,推荐4款好用的录屏软件
- Navicat Premium 11.0.19中文破解版 安装
- 摄像头网络模组的使用
- JAVA学习导图、思维导图
- 工欲善其事,必先利其器!idea最详细的Debug技巧及方法,让你定位bug如探囊取物!
- Android P SELinux (二) 开机初始化与策略文件编译过程
- 汉澳sinox2019操作系统AI企业版发布
- PyCharm使用技巧:Ctrl + /(多行注释)
- [极客大挑战 2019]Http1(BUCTF在线评测)
- c语言中变量赋值使用什么运算符,C语言基础学习运算符-赋值运算符
- flv.js php,B站视频开源代码flv.js+HTML5无flash播放视频