错误产生:

private Context mcontext;
@Override
protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext();
System.out.println("mcontext=" + mcontext);
}
  1. private Context mcontext;
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext();
  4. System.out.println("mcontext=" + mcontext);
  5. }
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相关推荐

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. android Unable to add window -- token null is n...

    2019独角兽企业重金招聘Python工程师标准>>> 问题的原因:调用了getApplicationContext()复制给你的context 解决方法:将activity赋值co ...

  6. Unable to add window token null is not valid is your activity running

    莫名其妙的报错 错误原因是不在主线程调用了弹窗方法 解决方法很简单 创建Handler static final int REFRESH_COMPLETE = 0X1112; private Hand ...

  7. 自定义对话框 提示:Unable to add window token null is not for an application

    这是因为在new Dialog(context);的时候传入的context是通过getApplicationContext()获得的,这样就会报错. 把context的获得方式改为MainActiv ...

  8. AlertDialog Unable to add window token null is

    2019独角兽企业重金招聘Python工程师标准>>> AlertDialog.Builder参数应该是Activity而不是getApplicationContext(); 转载于 ...

  9. Unable to add window -- token null is not for an application

    导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApp ...

最新文章

  1. 中科院等发布《2017研究前沿》 中国25个前沿表现卓越 居全球第二
  2. 【090】Excel VBA 基础
  3. android杀死进程
  4. 有了内阻值,怎么判断电池是否健康?
  5. 【LeetCode】TreeNode类实现解析(java实现)
  6. u盘pe无人值守linux,从U盘无人值守安装linux操作系统(纯实践笔记
  7. Android 沉浸式状态栏完美解决方案
  8. python 关于main函数以及if __name__=='__main__'的理解
  9. 一直弹出adb已停止工作(远程主机强迫关闭现有的连接)的最简单完美解决法
  10. 亲测有效,推荐4款好用的录屏软件
  11. Navicat Premium 11.0.19中文破解版 安装
  12. 摄像头网络模组的使用
  13. JAVA学习导图、思维导图
  14. 工欲善其事,必先利其器!idea最详细的Debug技巧及方法,让你定位bug如探囊取物!
  15. Android P SELinux (二) 开机初始化与策略文件编译过程
  16. 汉澳sinox2019操作系统AI企业版发布
  17. PyCharm使用技巧:Ctrl + /(多行注释)
  18. [极客大挑战 2019]Http1(BUCTF在线评测)
  19. c语言中变量赋值使用什么运算符,C语言基础学习运算符-赋值运算符
  20. flv.js php,B站视频开源代码flv.js+HTML5无flash播放视频

热门文章

  1. HDU-1028 Ignatius and the Princess III(生成函数)
  2. fastjson的@JSONField注解
  3. jquer 的简输出
  4. ABP理论学习之依赖注入
  5. 暴力求解——最大乘积 Maximum Product,UVa 11059
  6. 分离数据库(Detach database).
  7. POJ3009 Curling 2.0
  8. 常搓八个部位可以防衰老 - 健康程序员,至尚生活!
  9. pipenv 虚拟环境新玩法
  10. 团队作业8——第二次项目冲刺(Beta阶段)博客汇总