Search code examples
androidandroid-resourcessettext

String resource ID error when setting text in edit text


I have the following code.

if (j == 0) { // Age units.
    if (button.equals(findViewById(R.id.years)))
        q19Text.setText(yearsDiff);

    if (button.equals(findViewById(R.id.months)))
        q19Text.setText(monthsDiff);

    if (button.equals(findViewById(R.id.weeks)))
        q19Text.setText(daysDiff);

    if (button.equals(findViewById(R.id.days)))
        q19Text.setText(weeksDiff);
}

Button is a radio button. Any one that I click gives me this error

android.content.res.Resources$NotFoundException: String resource ID #0x2344

But, as you can see, I'm not trying to access the strings resource file. I'm trying to set the text of an already instantiated edit text.

Why am I getting this error?


Solution

  • You're using the setText(int id) method. Cast your integer to String and you should be fine. You can also add .setText("" + weeksDiff) to you code and it will treat it as string