码迷,mamicode.com
首页 > 其他好文 > 详细

由于一个粗心造成的RuntimeException

时间:2016-01-22 17:14:37      阅读:218      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!