Unable to add window -- token null is not for an application
2014-11-07 22:23
483 查看
代码中出现如下错误:android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application分析:问题在于new AlertDialog.Builder(Context),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApplicationContext()获得的Context,而必须使用Activity的Context对象,因为只有一个Activity才能添加一个窗体。 解决方法:将new AlertDialog.Builder(Context context)中的参数用Activity的Context对象即可弹出确认框 new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.confirm_title)
.setMessage(R.string.confirm_content)
.setPositiveButton(R.string.confirm_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int arg1) {
dialogInterface.dismiss();
masterClear(getApplicationContext());
}
})
.setNegativeButton(R.string.confirm_cancel, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int arg1) {
dialogInterface.cancel();
}
}).show();
.setTitle(R.string.confirm_title)
.setMessage(R.string.confirm_content)
.setPositiveButton(R.string.confirm_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int arg1) {
dialogInterface.dismiss();
masterClear(getApplicationContext());
}
})
.setNegativeButton(R.string.confirm_cancel, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int arg1) {
dialogInterface.cancel();
}
}).show();
相关文章推荐
- 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
- AlertDialog显示错误 Unable to add window token null is not for an application
- Android开发之关于“Unable to add window - token null is not for an application ”的异常
- Android酱油笔记之关于AlertDialog的Unable to add window token null is not for an application解决办法
- AlertDialog显示错误 Unable to add window token null is not for an application
- 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
- Unable to add window -- token null is not for an application:
- Unable to add window -- token null is not for an application
- Unable to add window -- token null is not for an application
- android AlertDialog显示错误 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
- AlertDialog显示错误 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
- Unable to add window -- token null is not for an application
- Android自用-----WindowManager$BadTokenException: Unable to add window -- token null is not for an application
- android使用AlertDialog提示 Unable to add window -- token null is not for an application的解决方案
- Unable to add window -- token null is not for an application错误的解决方法
- Dialog(四)——报错Unable to add window -- token null is not for an application