Resources NotFoundException
The below Resources$NotFoundException log results from user error and is easily fixed.
Uncaught handler: thread main exiting due to uncaught exception android.content.res.Resources$NotFoundException: String resource ID #0x1 at android.content.res.Resources.getText(Resources.java:205) at android.widget.TextView.setText(TextView.java:2809)
I get this error when I am trying to set a View’s text using an integer value like:
view.setText(iSomeInteger) // This is incorrect !
Instead, to set the text of a view using an integer, you need to do:
view.setText(Integer.toString(iSomeInteger)) // setText with an int
The problem is that setText(int) is reserved for string resource ids, like:
view.setText(R.string.someStringId) // setText with a string resource id
The last part of this puzzle is when you want to concatenate a string resource with other text, you need to use getString(int). Otherwise you will end up with the string resource id (not the string itself) as part of your new text:
// concatenate a string with a string resource
view.setText("Some Text: " + getString(R.string.someStringId))
| Print article | This entry was posted by Conroy Whitney on 2010-05-27 at 01:36, and is filed under Developer How-To. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
Thx dude, u got me looking at setText, hate it when i need to make it a string, thx though , cheers
about 1 year ago
Wow I just spent an hour scratching my head till I googled the right thing and found this post. Thanks!
about 11 months ago
Thanks for posting this yaar. It was seriously very helpful.
about 9 months ago
Thanks a lot, It’s very helpful, Android itself should says the meaningful exception.
about 9 months ago
Hats Off!!!!!
You made my day!!!!!!