試圖讓機器人把握throught大書呆子牧場指導,我遇到了這個例子:的Android TextView的資源沒有發現
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
mQuestionTextView = (TextView) findViewById(R.id.question_text_view);
int question = mQuestionBank[mCurrentIndex].getTextResId();
mQuestionTextView.setText(question);
其中mQuestionBank
private Question[] mQuestionBank = new Question[] {
new Question(R.string.question_oceans, true),
new Question(R.string.question_mideast, false),
new Question(R.string.question_africa, false),
new Question(R.string.question_americas, true),
new Question(R.string.question_asia, true),
};
和那些已經在被定義strings.xml
<string name="question_oceans">The Pacific Ocean is larger than the Atlantic Ocean.</string>
<string name="question_mideast">The Suez Canal connects the Red Sea and the Indian Ocean.</string>
<string name="question_africa">The source of the Nile River is in Egypt.</string>
<string name="question_americas">The Amazon River is the longest river in the Americas.</string>
<string name="question_asia">Lake Baikal is the world\'s oldest and deepest freshwater lake.</string>
但是我得到一個資源未找到異常。 (textResId是問題類的第一場)
編輯:
問題類
public class Question {
private int mTextResId;
private boolean mAnswerTrue;
public Question(int mTextResId, boolean mAnswerTrue) {
mTextResId=mTextResId;
mAnswerTrue=mAnswerTrue;
}
public int getTextResId() {
return mTextResId;
}
public void setTextResId(int textResId) {
mTextResId = textResId;
}
public boolean isAnswerTrue() {
return mAnswerTrue;
}
public void setAnswerTrue(boolean answerTrue) {
mAnswerTrue = answerTrue;
}
什麼是mCurrentIndex? –
發佈您的logcat輸出 –
mCurrentIndex是一個私人int = 0 – Boulbi