안드로이드 프로젝트의 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>
나는 나의 자바 클래스
endLevelLabel.setText(R.string.level_reached_label + level);
endInfoLabel.setText(R.string.endgame_textP1 + score + R.string.endgame_textP2 + gameTime + R.string.endgame_textP3);
첫 번째 줄은 잘 실행하지만, 두 번째 줄이 오류 (프로그램이 주석 라인 2와 함께 작동) 제공 한이 라인 문자열을 호출 :
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.web.mathtaketwo/com.web.mathtaketwo.EndGame}: android.content.res.Resources$NotFoundException: String resource ID #0x7d1500be
이 문자열이 작동하지 않게 된 것은 무엇입니까? 변수와 결합 된 1 줄에 여러 문자열을 사용하려고하기 때문에 그것이 있습니까? 왜 다른 문자열은 잘로드됩니까?
참고 : 문제가 R.string.xxx
반환 문자열의 ID입니다 그래서 기본적으로
TextView endInfoLabel = (TextView)findViewById(R.id.endInfoLabel);
TextView endLevelLabel = (TextView)findViewById(R.id.endLevelLabel);
R.string.endgame_textP1 문자열이 아니라 더 나은 – Selvin