码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-11-25 12:49:05      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:android   exception   

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

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);

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

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

标签:android   exception   

原文地址:http://blog.csdn.net/zhufuing/article/details/41478205

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!