关于AlertDialog.Builder(Context context)中所应传入的context
错误报告:
10-20 14:34:46.565: E/AndroidRuntime(23098): FATAL EXCEPTION: main
10-20 14:34:46.565: E/AndroidRuntime(23098): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
问题分析:
在AlertDialog.Builder(Context context)方法中我传入了getApplicationContext(),一般情况下传入整个应用的上下文是没有问题的,但是AlertDialog的构建是需要一个父Activity的,因此必须传入一个准确的Activity的上下文。
解决办法:
将getApplicationContext()改为xxxActivity.this
关于AlertDialog.Builder(Context context)中所应传入的context的更多相关文章
- Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder
Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder 转自:ht ...
- AlertDialog.Builder中的setMultiChoiceItems中的事件处理
因为实习项目中涉及到类似于时钟设置闹钟反复时间的原因须要使用对话框的方式呈现.因为DialogFragment眼下还没实验出嵌套Fragment的方法.所以临时先用AlertDialog.Builde ...
- Spring context:component-scan中使用context:include-filter和context:exclude-filter
Spring context:component-scan中使用context:include-filter和context:exclude-filter XML: <?xml version= ...
- hadoop中setup,cleanup,run和context讲解
hadoop 执行中的setup run cleanup context的作用1.简介1) setup(),此方法被MapReduce框架仅且执行一次,在执行Map任务前,进行相关变量或者资源的集中初 ...
- 将 context node 中的内容 分配给 desing layer
1 将 context node 中的内容 分配给 desing layer 选中context node 右键>assignment to design layer.
- 在tomcat下context.xml中配置各种数据库连接池(JNDI)
1. 首先,需要为数据源配置一个JNDI资源.我们的数据源JNDI资源应该定义在context元素中.在tomcat6版本中,context元素已经从server.xml文件中独立出来了,放在一个 ...
- 在tomcat下context.xml中配置各种数据库连接池
作者:郑文亮 Tomcat6的服务器配置文件放在 ${tomcat6}/conf 目录底下.我们可以在这里找到 server.xml 和 context.xml.当然,还有其他一些资源文件.但是在在本 ...
- 区分DDD中的Domain, Subdomain, Bounded Context, Problem/Solution Space
区分DDD中的Domain, Subdomain, Bounded Context, Problem/Solution Space 译自: Domain, Subdomain, Bounded Con ...
- 设计模式-State(行为模式)-很好的实现了对象的状态逻辑与动作实现的分类,状态逻辑在State的派生类实现,动作可以放在Context类中实现。
以下代码来源: 设计模式精解-GoF 23种设计模式解析附C++实现源码 //Context.h #pragma once class State; class Context { public: C ...
随机推荐
- 338. Counting Bits
https://leetcode.com/problems/counting-bits/ 给定一个非负数n,输出[0,n]区间内所有数的二进制形式中含1的个数 Example: For num = 5 ...
- ACID属性区别
事务是指对系统进行的一组操作,为了保证系统的完整性,事务需要具有ACID特性,具体如下: 1. 原子性(Atomic) 一个事务包含多个操作,这些操作要么全部执行,要么全都不执行.实现事务的原 ...
- javascript export excel
<input type="button" onclick="tableToExcel('tablename', 'name')" value=" ...
- 21. Merge Two Sorted Lists —— Python
题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- 土地购买(bzoj 1597)
Description 农夫John准备扩大他的农场,他正在考虑N (1 <= N <= 50,000) 块长方形的土地. 每块土地的长宽满足(1 <= 宽 <= 1,000, ...
- JDK7和JDK8一些重要新特性
jdk7新特性(部分) switch支持字符串 List AutoCloseable接口实现自动关闭,在try()中 新增获取环境信息的工具方法,getJavaHomeDir,getUserHomeD ...
- Beginning Scala study note(3) Object Orientation in Scala
1. The three principles of OOP are encapsulation(封装性), inheritance(继承性) and polymorphism(多态性). examp ...
- git rebase 和 merge的区别
- RadioButton(单选按钮)文字在按钮的左边
<RadioButton style="@style/CustomCheckboxTheme" android:layout_width="fill_parent& ...
- 关于 Lo、Hi、LoWord、HiWord
Cardinal 是 4 字节无符号的整型, 先看一个例数: Cardinal 例数: 4277991664 按字节划分: 第四字节 第三字节 第二字节 第一字节 二进制: 11111110 1111 ...