android.view.WindowManager$BadTokenException: Unable to add window — token null
来源:互联网 发布:网络光纤型号 编辑:程序博客网 时间:2024/06/06 02:54
导致报这个错是在于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(Context context)中的参数用Activity.this(Activity是你的Activity的名称)来填充就可以正确的创建一个Dialog了。
Java代码
- 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();
总结,
当我们访问当前应用的资源,启动一个新的activity的时候都需要提供Context。
Context是一个抽象基类,我们通过它访问当前包的资源(getResources、getAssets)和启动其他组件(Activity、Service、Broadcast)以及得到各种服务(getSystemService),当然,通过Context能得到的不仅仅只有上述这些内容。对Context的理解可以来说:Context提供了一个应用的运行环境,在Context的大环境里,应用才可以访问资源,才能完成和其他组件、服务的交互,Context定义了一套基本的功能接口,可以理解为一套规范,而Activity和Service是实现这套规范的子类,这么说也许并不准确,因为这套规范实际是被ContextImpl类统一实现的,Activity和Service只是继承并有选择性地重写了某些规范的实现。
0 0
- 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 is not for an applic
- android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an appli
- 试用dialog时碰到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 is not for an applic
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- 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 nul
- android.view.WindowManager$BadTokenException: Unable to add window -- token
- 解决android.view.WindowManager$BadTokenException: Unable to add window -- token .
- Android报错android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for
- worldcount程序java版本
- EXT2 文件系统
- oracle体系:
- Cookie
- stl各个容器的使用时机
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- CSS3快速上手之4:多重背景
- 简单易学的机器学习算法——极限学习机(ELM)
- 第七周项目3——负数把正数赶出队列
- 【并行计算】用MPI进行分布式内存编程(二)
- [LeetCode]258. Add Digits
- c# 中的file和fileinfo,directory和directoryinfo以及filesysteminfo
- 记事本的基本功能
- Java:常用标准库算法