当字符串资源存在时,android.content.res.Resources$NotFoundException

当字符串资源存在时,android.content.res.Resources$NotFoundException,android,string,resources,Android,String,Resources,在我的android项目中,我有几个字符串放在了android values/strings.xml文件中 <resources> <string name="level_reached_label">Level Reached: </string> <string name="endgame_textP1">You have scored </string> <string name="endgame_t

在我的android项目中,我有几个字符串放在了android values/strings.xml文件中

<resources>
    <string name="level_reached_label">Level Reached: </string>
    <string name="endgame_textP1">You have scored </string>
    <string name="endgame_textP2"> points in </string>
    <string name="endgame_textP3"> seconds </string>
</resources>
第一行运行正常,但第二行出现此错误(程序使用注释掉的第二行):

我做错了什么使这个字符串停止工作?是因为我试图在一行中使用多个字符串和变量组合吗?为什么其他字符串加载良好

注意:正在设置的两个对象是
TextView

TextView endInfoLabel = (TextView)findViewById(R.id.endInfoLabel);
TextView endLevelLabel = (TextView)findViewById(R.id.endLevelLabel);

好的,基本上问题是
R.string.xxx
只返回字符串的ID

当我尝试将ID(整数)插入字符串时,这会导致许多问题

相反,我应该做的是使用
getString()
函数,该函数返回指定id处的字符串:

getString(R.string.xxxx)
如果我使用
getString()
更改代码:

然后它就正常工作了。有关更多详细信息,请参阅我查看的其他主题:


R.string.endgame_textP1不是字符串,而是int
TextView endInfoLabel = (TextView)findViewById(R.id.endInfoLabel);
TextView endLevelLabel = (TextView)findViewById(R.id.endLevelLabel);
getString(R.string.xxxx)
endLevelLabel.setText(getString(R.string.level_reached_label) + (level));
endInfoLabel.setText(getString(R.string.endgame_textP1) + score + getString(R.string.endgame_textP2) + gameTime + getString(R.string.endgame_textP3));