[Android那些破事]Android的一些异常解决——不定时更新

记录解决的一些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的间距高度,使界面符号自己的要求。

解决办法:

  1. 代码的方法:listView.setDividerHeight(5); 表示每个item的间隔5个像素

  2. 直接在xml文件中设置:android:dividerHeight =“5dp”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值