Dialog(四)——报错Unable to add window -- token null is not for an application
2014-06-06 16:07
495 查看
/** * 问题描述: * 创建和显示对话框的时候报错 * Unable to add window -- token null is not for an application * * 问题修正: * 不可使用Builder builder=new Builder(getApplicationContext()); * 应该使用Builder builder=new Builder(MainActivity.this); */ private void showDialog(){ Dialog dialog; //正确 Builder builder=new Builder(MainActivity.this); //错误 //Builder builder=new Builder(getApplicationContext()); builder.setIcon(R.drawable.ic_launcher); builder.setTitle(getResources().getString(R.string.dialog_title)); builder.setMessage(R.string.dialog_message); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { } }); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { } }); dialog=builder.create(); dialog.show(); }
相关文章推荐
- Dialog(四)——报错Unable to add window -- token null is not for an application
- AlertDialog显示错误 Unable to add window token null is not for an application
- AlertDialog显示错误 Unable to add window token null is not for an application
- AlertDialog显示错误 Unable to add window token null is not for an application
- 在创建一个Dialog时,发生的错误: Unable to add window -- token null is not for an application
- Dialog Unable to add window -- token null is not for an application错误的解决方法
- Dialog throwing "Unable to add window — token null is not for an application” with getApplication()
- AlertDialog:Unable to add window -- token null is not for an application
- android报错——Unable to add window -- token null is not for an application
- AlertDialog显示错误 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出错)
- 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
- AlertDialog显示错误 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
- Unable to add window -- token null is not for an application
- Unable to add window -- token null is not for an application错误的解决方法