0

i have a multilanguage android app..I put this

<string name="FOOD_SUGGESTED">Top Ristoranti</string>

in res/values-it/strings.xml

and this

<string name="FOOD_SUGGESTED">Top Restaurants</string>

in res/values-en/strings.xml.

in java i use this values with

String suggested = getResources().getString(R.string.FOOD_SUGGESTED);
referenceTextView.setText("" + related.size() + " " + suggested);

Sometimes by Android Vitals i got this error

android.content.res.Resources$NotFoundException: 
    at android.content.res.Resources.getText (Resources.java:1178)
    at android.content.res.Resources.getString (Resources.java:1224)
    at com.a70division.blink.CardViews.GenericCardView.<init>(GenericCardView.java:78)
    at com.a70division.blink.Card.getViewForCard (Card.java:190)
    at com.a70division.blink.Card.<init> (Card.java:92)
    at com.a70division.blink.Fragments.DeckFragment.createCardView (DeckFragment.java:251)
    at com.a70division.blink.Fragments.DeckFragment.nextCard (DeckFragment.java:354)
    at com.a70division.blink.Fragments.DeckFragment.access$700 (DeckFragment.java:53)
    at com.a70division.blink.Fragments.DeckFragment$11.run (DeckFragment.java:429)

i can't understand where is the mistake

someone can help me?

Ettore Panini
  • 87
  • 1
  • 7

2 Answers2

1

Be sure that you have added that resource also under root path: res/values/strings.xml. If you do not do this, your application will crash if device's language is other than English(en) or Italian(it).

Also I will recommend you to define your resources IDs in lowercase(this just for name conventions):

<string name="food_suggested">Top Restaurants</string>

Finally, ensure that your string resources are enclosed between <resources> </resources>tags, this is mandatory:

<resources>
    <string name="food_suggested">Top Restaurants</string>
</resources>
AlexTa
  • 5,133
  • 3
  • 29
  • 46
-1

Please change your string name from caps to small chars.

like

<string name="food_suggested">Top Ristoranti</string>
<string name="food_suggested">Top Restaurants</string>

String suggested = getResources().getString(R.string.food_suggested);

Please try this way and let us know your feedback. Hope this will work.

Faldu Jaldeep
  • 545
  • 2
  • 15