---
title: "Dialog 出现的android.view.WindowManager$BadTokenException: Unable to add window异常"
author: "mfan"
date: "2012-09-11T01:54:43Z"
tags: []
categories: ["移动开发"]
slug: "dialog-android-view-windowmanager-badtokenexception-unable-to-add-window"
draft: false
lastmod: "2012-09-11T01:56:12Z"
id: 1675485
url: "https://mfan.iteye.com/blog/1675485"
---

Dialog异常：  
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

异常原因：  
new AlertDialog.Builder(Context context)中的参数不能用getApplicationContext()获得的context，而必须使用Activity,因为只有一个Activity才能添加一个窗体。

解决办法：  
例如 new AlertDialog.Builder(XXXActivity.this)