canvas.drawBitmap(mIconBitmap, null, mIconRect, null)这句报空指针
canvas.drawBitmap(mIconBitmap, null, mIconRect, null)这个语句在Eclipse上可以不报错,在Android Studio上会报错诶,求老师指导??
canvas.drawBitmap(mIconBitmap, null, mIconRect, null)这个语句在Eclipse上可以不报错,在Android Studio上会报错诶,求老师指导??
2015-05-18
AS在引用自定义布局的时候这样写 xmlns:hyman="http://schemas.android.com/apk/res-auto"
你可以测试你的值,canvas.drawBitmap(mIconBitmap,null, mIconRect,null);
在这语句中其实mIconBitmap是为空的 并没有拿到你自定义的任何控件属性;
/**
* 获取自定义属性的值
*
* @param context
* @param attrs
* @param defStyleAttr
*/
public ChangeColorIconWithText(Context context, AttributeSet attrs,
int defStyleAttr)
{
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.ChangeColorIconWithText);
Log.e("测试","a:"+a);
int n = a.getIndexCount();
Log.e("测试","a.getIndexCount():"+a.getIndexCount());
for (int i = 0; i < n; i++)
{
int attr = a.getIndex(i);
Log.e("测试","attr:"+attr);
.......
在进入for 之前 所有的值都是 0 ;你自己可以可以测试。
至于说改attrs 里面color;我倒是改了,但是 最后我是测到我并没有取到值后我改了我的引用,最后拿到值了就不报错了
06-21 10:26:08.459 24711-24711/com.weixin.weixin_liu E/测试: attr:1
06-21 10:26:08.460 24711-24711/com.weixin.weixin_liu E/测试: attr:2
06-21 10:26:08.460 24711-24711/com.weixin.weixin_liu E/测试: attr:3
06-21 10:26:08.481 24711-24711/com.weixin.weixin_liu E/测试: a:[0, 0, 1, 0, 0, 0, 3, 165, 5, 2130903040, 0, 160, 3, 20, -1, 0, 0, 0, 5, 3074, -1, 0, 0, 0, 0, 0, -1, 0, 1073746944, 0, 0, 0, -1, 0, 1073746944, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 18, 0, 5, 2131427416, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 5, 0, 0, 0, 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0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0]
06-21 10:26:08.481 24711-24711/com.weixin.weixin_liu E/测试: a.getIndexCount():3
举报