简体   繁体   中英

R.string Resources$NotFoundException Error on android app

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?

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM