异常:android.view.WindowManager$BadTokenException: Unable to add window
来源:互联网 发布:淘宝订单体检清洗 编辑:程序博客网 时间:2024/05/15 09:49
原址:http://aijiawang-126-com.iteye.com/blog/662336
错误产生:
- 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();
1 0
- 异常android.view.WindowManager$BadTokenException: Unable to add window解决方法
- android.view.WindowManager$BadTokenException: Unable to add window异常
- 关于异常:android.view.WindowManager$BadTokenException: Unable to add window
- 异常:android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window -- token nul
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window -- token
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window(转)
- 【已解决】android.view.WindowManager$BadTokenException: Unable to add window
- 解决android.view.WindowManager$BadTokenException: Unable to add window -- token .
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window --Unabletoaddwindow--tokenandroid
- 序列化
- ios10跳转系统设置界面失败
- 手机降噪麦克风为啥要设计在顶部?
- Spark Streaming Backpressure分析
- 为什么外包难做出好的APP?
- 异常:android.view.WindowManager$BadTokenException: Unable to add window
- jquery之$.each()
- Eclipse的debug
- App自动更新之通知栏下载
- 动态代码设置Textview的字体大小,引用Dimen资源
- HTTP常见状态码
- button的setClickable 和 setEnabled 区别
- const和readonly的区别
- liang个网站