android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
来源:互联网 发布:linux环境变量设置生效 编辑:程序博客网 时间:2024/05/17 07:07
错误产生:
导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApplicationContext()获得的Context,而必须使用Activity,因为只有一个Activity才能添加一个窗体。
解决方法:将new AlertDialog.Builder(Context context)中的参数用Activity.this(Activity是你的Activity的名称)来填充就可以正确的创建一个Dialog了。
- 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.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- iphone swipe left and right
- Makefile中$@应用举例
- MACH_FRIENDLY_ARM
- Linux中__init、__devinit等初始化宏
- 链栈的多进制应用
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- vc6.0添加ws2_32.lib文件的问题
- ajax 控件简述
- 10341 - Solve It 三分 + 浮点型函数用法
- STL容器的erase用法
- sizeof详解 - 很好的sizeof资料 A
- 投资意向书
- 抽象类和接口的最佳实践
- sizeof详解 - 很好的sizeof资料 B