java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3

来源:互联网 发布:网络课 编辑:程序博客网 时间:2024/06/05 02:25

前几天在编写一个自定义控件的时候,出现了这个这个异常:

Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3

然后定位到代码中的时候,发现是自定义控件中引用资源的时候报的错误,代码片段如下:

int iconId = mTypedArray.getInteger(R.styleable.TitleBar_icon, 0); iconIv.setImageResource(iconId);

在执行mTypedArray.getInteger()方法的时候出现报错,根据报错信息字面意思是因为获取的资源id无法转换为integer类型才报错的,于是我将getInteger()改为了getResourceId()方法,这回程序就运行正常了。

int iconId = mTypedArray.getResourceId(R.styleable.TitleBar_icon, 0);iconIv.setImageResource(iconId);

至于深层次的原因,我现在还不清楚,期待有人可以给我解答,谢谢~

0 0
原创粉丝点击