android.content.res.Resources$NotFoundException: String resource ID #0x3c

今天在自定义倒计时控件时,总是报错如下:

android.content.res.Resources$NotFoundException: String resource ID #0x3c

报错行是:

CountDownTextView.this.setText(downTime);

错误原因:
我的downTime是int类型的,用在setText中的时候,他会当成是R.String.xxx,然后去寻找。他当然找不到了!哈哈哈。

正确格式:

CountDownTextView.this.setText(String.valueOf(downTime));

分析:setText函数是可以传入资源id的。

@android.view.RemotableViewMethod
public final void setText(int resid) {
    setText(getContext().getResources().getText(resid));
}

你可能感兴趣的:(Android开发)