Resources Not Found Exception

In Android a very common error you can get is Resources Not Found Exception, has you can see below:

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)

This happens when you try to set a View’s text with a integer value, yes the .setText(int) function exists, but it is reserved for string resource ids only, the ones you set in strings.xml in values, for example: R.string.myStringId
This is why the setText(int) function exists:

myView.setText(R.string.myStringId); //this works

But if you’re doing something like

myView.setText(someInt); // this is wrong!!

You will get this error, if you really want to write someInt in the view’s text, you will need to do this:

myView.setText(Integer.toString(someInt)); //this works

And if you want to write a text concatenating a string with a resource id of another string?
Well, in that case you use the .getString(int) function, like so:

myView.setText("Some Text: " + getString(R.string.myStringId)); 

4 thoughts on “Resources Not Found Exception

  1. Someone essentially help to make significantly posts I might state. This is the first time I frequented your web page and so far? I surprised with the research you made to create this actual submit amazing. Magnificent activity! ecdbkedbkcag

    • Thank you very much, I saw many people getting this error and not knowing what it was, and was hard to find a straight answer, so here it is 🙂 glad I could help

Leave a comment