android.view.WindowManager$BadTokenException: Unable to add window — token null
来源:互联网 发布:办公椅品牌 知乎 编辑:程序博客网 时间:2024/06/08 13:47
- 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();
0 0
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an applic
- android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an appli
- 试用dialog时碰到android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an applic
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- [ERROR]android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window -- token nul
- android.view.WindowManager$BadTokenException: Unable to add window -- token
- 解决android.view.WindowManager$BadTokenException: Unable to add window -- token .
- Android报错android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for
- C Tips: 比较函数 int(*cmp)(const void *, const void *)
- ODBC数据导入
- 记录一下fedora20安装后,需要安装的一些必备的软件包
- 装饰者模式---汉堡实例
- Base-calling for next-generation sequencing platforms (译文)
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- 利用Theme自定义Activity间的切换动画
- 大家好啊、新人报道
- C/C++混编的命令行加密工具
- request中出现乱码问题的解决办法
- C Tips: 排序算法:插入排序(Insert sorting)
- 相遇在这茫茫的网海里。你在天涯,我在海角
- POJ 3278:Catch That Cow 抓住那头牛
- POJ 2185 Milking Grid(KMP:循环节加强版)