首页 > 其他 > 详细

由于一个粗心造成的RuntimeException

时间:2016-01-22 17:12:55      阅读:165      评论:0      收藏:0      [点我收藏+]

今天在测试时候,老是有一个TextView报错,以下是错误日志:

java.lang.RuntimeException:

Unable to resume activity {com....Activity}: android.content.res.Resources$NotFoundException: String resource ID #0x0

Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0

at com.gidoor.runner.ui.main.OrderManagerActivity.setOrderCountValue(...Activity.java:133)

定位到相关代码:

技术分享

罪魁祸首就是reservedCount这个变量(int类型)。

再来看看TextView.setText的方法:

final void

setText(int resid)

final void

setText(char[] text, int start, int len)

Sets the TextView to display the specified slice of the specified char array.

final void

setText(int resid, TextView.BufferType type)

final void

setText(CharSequence text)

Sets the string value of the TextView.

void

setText(CharSequence text, TextView.BufferType type)

Sets the text that this TextView is to display (see setText(CharSequence)) and also sets whether it is stored in a styleable/spannable buffer and whether it is editable.

看到这里,就知道了,原来这执行这行代码的时候,系统去R.Java里面寻找ID为0(上面的reservedCount值为0)的String,没有找到。

到此,终于排雷成功。It’s funny!

由于一个粗心造成的RuntimeException

原文:http://www.cnblogs.com/ithaibo-sit/p/5151380.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!