简体   繁体   English

R.string Resources $ NotFoundException在Android应用程序上的错误

[英]R.string Resources$NotFoundException Error on android app

i have a multilanguage android app..I put this 我有一个多语言的android应用程序。

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

in res/values-it/strings.xml 在res / values-it / strings.xml中

and this 和这个

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

in res/values-en/strings.xml. 在res / values-en / strings.xml中。

in java i use this values with 在Java中我使用此值

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

Sometimes by Android Vitals i got this error 有时,通过Android Vitals我遇到了此错误

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 . 确保您还在根路径下添加了该资源: 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). 如果您不这样做,那么如果设备的语言不是英语(en)或意大利语(it),则应用程序将崩溃。

Also I will recommend you to define your resources IDs in lowercase(this just for name conventions): 另外,我建议您以小写形式定义资源ID(仅用于名称约定):

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

Finally, ensure that your string resources are enclosed between <resources> </resources> tags, this is mandatory: 最后,确保您的字符串资源包含在<resources> </resources>标记之间,这是强制性的:

<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. 希望这会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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