android.view.WindowManager$BadTokenException: Unable to add window — token null
2013-04-16 17:38
369 查看
new AlertDialog.Builder(getApplicationContext())
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("提示")
.setMessage("上下文报错")
.setPositiveButton("Yes", positiveListener).setNegativeButton(
"No", negativeListener).create().show();
错误原因:AlertDialog.Builder(getApplicationContext())
不能用应用程序的上下文,应该用当前Activity的Context,因为只有一个Activity才能添加一个Dialog
正确应该:
new AlertDialog.Builder(MainActivity.this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("提示")
.setMessage("一个Activity才能添加一个Dialog")
.setPositiveButton("Yes", positiveListener).setNegativeButton(
"No", negativeListener).create().show();
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("提示")
.setMessage("上下文报错")
.setPositiveButton("Yes", positiveListener).setNegativeButton(
"No", negativeListener).create().show();
错误原因:AlertDialog.Builder(getApplicationContext())
不能用应用程序的上下文,应该用当前Activity的Context,因为只有一个Activity才能添加一个Dialog
正确应该:
new AlertDialog.Builder(MainActivity.this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("提示")
.setMessage("一个Activity才能添加一个Dialog")
.setPositiveButton("Yes", positiveListener).setNegativeButton(
"No", negativeListener).create().show();
相关文章推荐
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- 试用dialog时碰到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 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
- Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootI
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is yo
- android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an appli
- Caused by: android.view.WindowManager$BadTokenException: Unable to add window -
- AlertDialog.Builder发生:android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token
- android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@1ccfe
- android.view.WindowManager$BadTokenException: Unable to add window
- 解决: android.view.WindowManager BadTokenException:Unable to add Window.Is your activity running?