Android自用-----WindowManager$BadTokenException: Unable to add window -- token null is not for an application
转自http://www.cnblogs.com/oakpip/archive/2011/04/06/2007310.html
错误产生:
- private Context mcontext;
- @Override
- protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext();
- System.out.println("mcontext=" + mcontext);
- }
- new AlertDialog.Builder(mcontext)
- .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();
导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApplicationContext()获得的Context,而必须使用Activity,因为只有一个Activity才能添加一个窗体。
解决方法:
将new AlertDialog.Builder(Context context)中的参数用Activity.this(Activity是你的Activity的名称)来填充就可以正确的创建一个Dialog了。
- 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自用-----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
原博客地址:http://aijiawang-126-com.javaeye.com/blog/662336 在Activity中newSpinner是我把mContext传入,但是出了 andr ...
- Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
在广播中启动一个Dialog时出现如下错误信息:Caused by: android.view.WindowManager$BadTokenException: Unable to add windo ...
- android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an applic
之前遇到过这样的问题, 04-12 10:40:33.302: E/AndroidRuntime(17213): Caused by: android.view.WindowManager$BadTo ...
- Activity has leaked window that was originally added -界面退出时未关闭对话框异常 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? -
退出Activity时弹出登录框,点击确定finish当前Activity,结果报了这个错,随后查找资料知道 原因: 是因为退出Activity时没有关闭弹出框,出现了这个错误 解决方法: 只需要在a ...
- Unable to add window -- token null is not for an application错误的解决方法 android开发
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not f ...
- bug_ _ android.view.WindowManager$BadTokenException: Unable to add window -- token
========4 关于android的一个常见错误:Unable to add window --token is not valid android.view.WindowManage ...
- Unable to add window -- token null is not for an application
导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApp ...
- 自定义对话框 提示:Unable to add window token null is not for an application
这是因为在new Dialog(context);的时候传入的context是通过getApplicationContext()获得的,这样就会报错. 把context的获得方式改为MainActiv ...
- 关于ProgressDialog.show抛出android.view.WindowManager$BadTokenException: Unable to add window
下午摆弄ProgressDialog,进入就抛错:android.view.WindowManager$BadTokenException: Unable to add window -- token ...
随机推荐
- 苹果手机微信上form表单提交的问题
场景:前端页面请求后端php,返回带form表单dom元素,然后将其追在页面上,返回的html字段中包含表单自动提交的代码,想法是将带有表单自动提交的dom元素追加到页面上,然后表单自动提交到另外一个 ...
- lua 字符串 正则表达式 转义 特殊字符
string.gsub 函数有三个参数:目标串,模式串,替换串.基本作用是用来查找匹配模式的串,并将使用替换串其替换掉: s = string.gsub("Lua is good" ...
- 编写base64图片文件
base64编码代替css背景图片在网站上应用是很广泛的,例如:loading gif图片,天猫加载时那只猫等等. 因为base64图片可以减少http请求,所以我们经常会把不经常改动的,独立的,尺寸 ...
- AmazeUI 框架知识点-组件
1.Badge 默认:添加 .am-badge class 到 <div> 或者 <span> 元素. 圆角:在默认样式的基础上添加 .am-radius class. 椭圆: ...
- poj3629
//(队列)poj3629 /* #include <iostream> #include <queue> #include <algorithm> using n ...
- JeeSite学习笔记~代码生成原理
1.建立数据模型[单表,一对多表,树状结构表] 用ERMaster建立数据模型,并设定对应表,建立关联关系 2.系统获取对应表原理 1.怎样获取数据库的表 genTableForm.jsp: < ...
- .保护Express应用程序
毫无疑问,Node.js已经变的愈加成熟,尽管这样,开发者仍然缺乏大量的安全指南.在这篇文章中,我将分享一些有关Node.js安全要点给大家,希望大家能够谨记于心. 1.避免使用Eval Eval并不 ...
- PHP的FastCGI
CGI全称是“通用网关接口”(Common Gateway Interface), 它可以让一个客户端,从网页浏览器向执行在Web服务器上的程序请求数据. CGI描述了客户端和这个程序之间传输数据的一 ...
- 微软发布TX(LINQ To Logs And Traces)
微软开源技术公司于发布了Tx,这是一个Apache 2协议的开源项目,可以使用日志/跟踪文件辅助调试,以及创建实时监控和告警系统. 下面是几个引人关注的功能-- 允许在原始事件源上使用LINQ 允许在 ...
- 我的ORM汇总
MyOql是我写的ORM,目前仅支持 MSSql2005+ ,从2009年到今天,已使用过不少项目,之后会写 其它关系数据库的解析器: MySql,Sqlite,Oracle 等. 代码地址(最新版) ...