记录解决的一些Android异常,由于这些异常比较好解决,不值得再写一篇新文章来描述,因此记录在这里,不定时更新。
Unable to add window – token null is not for an application
在新建Dialog时发生的错误,代码如下:
new AlertDialog.Builder(getApplicationContext())
.setTitle("加为好友")
.setIcon(R.drawable.icon_geo)
···
.show();
查询SDK帮助文档:
Return the context of the single, global Application object of the current process. This generally should only be used if you need a Context whose lifecycle is separate from the current context, that is tied to the lifetime of the process rather than the current component.
解决办法:
将getApplicationContext()
换成Activity.this
,就是你自己类的名字。
Failure [INSTALL_FAILED_OLDER_SDK]
运行的时候在DDMS中显示:
pkg: /data/local/tmp/com.example.leon.myapplication
Failure [INSTALL_FAILED_OLDER_SDK]
不管是模拟器还是真机,其实就是SDK 版本不匹配,调试编码的sdk版本过高。
解决办法:在build.gradle
中将minSdkVersion 19
改小一点就行。
修改ListView中Item的间距
每次设置listview的时候,item的间距默认为“0dp”很是不好看,因此可以设置item的间距高度,使界面符号自己的要求。
解决办法:
代码的方法:listView.setDividerHeight(5); 表示每个item的间隔5个像素
直接在xml文件中设置:android:dividerHeight =“5dp”