android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
来源:互联网 发布:试卷分析软件 编辑:程序博客网 时间:2024/05/16 15:02
在Activity中newSpinner是我把mContext传入,但是出了android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application这个错误,参考了达人的文章终于搞定
private Context mcontext;@Overrideprotected 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
- CADOCommand错误“ORA-01008:并非所有变量都已绑定”的解决方案
- Java流与文件操作
- Google雇佣Google+源代码发掘者Florian Rohrweck
- HTML排列清单控制标记
- 欧洲数值天气预报文件拆分方法
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- ELF Hash算法
- gethibernatetemplate find条件查询方法
- OpenQRM的安装与评测(一. 安装与部署)
- ORACLE删除表空间中的所有表
- Linux C/C++ 内存泄漏检测工具Valgrind
- Core Data--Data Migration
- mouse添加鼠标移出移入事件 两种方法
- oracle数据文件被误删除后的灾难处理方法