我是初学者。我无法解决这两个问题:
1:
错误:(20,20)错误:找不到符号变量mQuestionBank
2:
错误:(20,20)错误:找不到符号变量mQuestionBank
代码:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class QuizActivity extends AppCompatActivity {
private android.widget.Button mTrueButton;
private android.widget.Button mFalseButton;
private Button mNextButton;
private TextView mQuestionTextView;
private int mCurrentIndex = 0;
private void updateQuestion() {
int question;
question = mQuestionBank[mCurrentIndex].getQuestion();
mQuestionTextView.setText(question);
}
private void checkAnswer(boolean userPressedTrue) {
boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion();
int messageResId = 0;
if (userPressedTrue == answerIsTrue) {
messageResId = R.string.correct_toast;
} else {
messageResId = R.string.incorrect_toast;
}
Toast.makeText(this, messageResId , Toast.LENGTH_SHORT)
.show();
}
private TrueFalse[] mQuesionBank = new TrueFalse[] {
new TrueFalse(R.string.question_1, false),
new TrueFalse(R.string.question_2, true),
new TrueFalse(R.string.question_3, false),
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
mQuestionTextView = (TextView)findViewById(R.id.question_text_view);
mTrueButton = (android.widget.Button)findViewById(R.id.true_button);
mTrueButton.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
checkAnswer(true);
}
});
mFalseButton = (android.widget.Button)findViewById(R.id.false_button);
mFalseButton.setOnClickListener(new android.view.View.OnClickListener() {
public void onClick(android.view.View v) {
checkAnswer(false);
}
});
mNextButton = (Button)findViewById(R.id.next_button);
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
updateQuestion();
}
});
updateQuestion();
}
}
我将非常感谢那些能够清晰明确地解释的人!
答案 0 :(得分:1)
你输错了
private TrueFalse[] mQuesionBank = new TrueFalse[] {
new TrueFalse(R.string.question_1, false),
new TrueFalse(R.string.question_2, true),
new TrueFalse(R.string.question_3, false),
};
mQuesionBank中缺少 t 。它应该是mQuestionBank。