错误信息:
android TextView报错:Caused by: android.content.res.Resources$NotFoundException: String resource ID #
原因:
因为TextView的setText(int)方法传值的需要是资源的id,如果传成了自己想展示的int就会找不到相关资源而报错!
源码分析:
public final void setText(@StringRes int resid) {
setText(getContext().getResources().getText(resid));
mTextSetFromXmlOrResourceId = true;
mTextId = resid;
}
getContext().getResources().getText(resid),获取的资源的数据,所以必须要传资源的id,比如R.string.tv_name等。
解决办法:
如果想展示自己的int数据的话,就要转化成String.value(int),string类型,就不会报错了。
2319




被折叠的 条评论
为什么被折叠?



