Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

在广播中启动一个Dialog时出现如下错误信息:Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

在代码中添加了dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);错误信息没有消除,

此时在Manifest.xml文件中添加系统权限,并添加:

允许应用使用TYPE_SYSTEM_ALERT来打开窗口,并将窗口显示于其他应用的顶端

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

的权限,对话框可以起来了。

时间: 2024-10-14 06:25:19

Caused by: android.view.WindowManager$BadTokenException: 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

原博客地址:http://aijiawang-126-com.javaeye.com/blog/662336 在Activity中newSpinner是我把mContext传入,但是出了 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application这个错误,参考了达人的文章终于搞定. [java] view plaincopy private C

兔子--android.view.windowmanager BadTokenException :unable to add window token null is not for applica

导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApplicationContext()获得的Context,而必须使用Activity,因为只有一个Activity才能添加一个窗体. 环境变量传入错误,不能使application的环境,应该是Activity的环境 new AlertDialog.Builder(MyActivity.this) .

Android自用-----WindowManager$BadTokenException: Unable to add window -- token null is not for an application

转自http://www.cnblogs.com/oakpip/archive/2011/04/06/2007310.html 错误产生: private Context mcontext; @Override protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext(); System.out.println("mcontext=" + mcontext); } new A

bug_ _ android.view.WindowManager$BadTokenException: Unable to add window -- token

android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running?at android.view.ViewRootImpl.setView(ViewRootImpl.java:546)at android.view.WindowManagerImpl.addView(WindowManagerImp

关于ProgressDialog.show抛出android.view.WindowManager$BadTokenException: Unable to add window

下午摆弄ProgressDialog,进入就抛错:android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application,让我百思不得其解.我这使用这种方法实现的进度对话框:proDialog = ProgressDialog.show(getApplicationContext(), "sadfs", "dddddd",tr

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 分析: 问题在于new AlertDialog.Builder(Context),虽然这里的参数是AlertDialog.Builder(Context context) 但我们不能使用getApplicationContext()获得的Context,而必须使用

bug_android.view.WindowManager$BadTokenException: Unable to add window -- token

========5 java.lang.IllegalArgumentException: View not attached to window manager at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:653) at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:349) at android.view.Wi

android.view.WindowManager$BadTokenException: Unable to add window

解决方法:AlertDialog.Builder(xxx.this) => AlertDialog.Builder(this.getParent()) 或(this)改为(xxx.this)

WindowManager$BadTokenException: Unable to add window permission denied for this window type

10-11 11:47:27.472: E/AndroidRuntime(12804): java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.zhl.classguiding/cn.zhl.classguiding.XueanPdfActivity}: android.view.WindowManager$BadTokenException: Unable to add window [email prote