2016-03-14 92 views
-5

我是初學者。我不解決這兩個問題:與Android Studio有關的問題

1:

Error:(20, 20) error: cannot find symbol variable mQuestionBank

2:

Error:(20, 20) error: cannot find symbol variable 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(); 

    } 
} 

我會很感激那些誰都會理解地並明確解釋!

+1

您尚未在您的代碼中的任何位置定義'mQuestionBank' –

+0

如何使它正確? –

+0

你在哪裏定義這些問題?它看起來應該是一個整數數組,但是你永遠不會定義它或給它任何值。即使你只是添加'private int [] mQuestionsBank = new int [???]',你仍然只能得到一個填充了零的數組。你想要什麼? (注意'???'應該是數組的大小) –

回答

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失蹤。它應該是mQuestionBank。