title: java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3
body: <p>How can I fix the error of IndexOutOfBoundsException?
  I am creating a quiz type application but its forces close whenever i finish answering the questions and proceed to the ResultActivity. 
  Please help me. Thanks!</p>
  
  <pre><code>public class QuizActivity extends Activity {
  List&lt;Question&gt; quesList;
  int score=0;
  int qid=0;
  Question currentQ;
  TextView txtQuestion;
  RadioButton rda, rdb, rdc;
  Button butNext;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.test);
      DBHelper db=new DBHelper(this);
      quesList=db.getAllQuestions();
      currentQ=quesList.get(qid);
      txtQuestion=(TextView)findViewById(R.id.textView1);
      rda=(RadioButton)findViewById(R.id.radio0);
      rdb=(RadioButton)findViewById(R.id.radio1);
      rdc=(RadioButton)findViewById(R.id.radio2);
      butNext=(Button)findViewById(R.id.button1);
      setQuestionView();
      butNext.setOnClickListener(new View.OnClickListener() {     
          @Override
          public void onClick(View v) {
              RadioGroup grp=(RadioGroup)findViewById(R.id.radioGroup1);
              RadioButton answer=(RadioButton)findViewById(grp.getCheckedRadioButtonId());
              Log.d("yourans", currentQ.getANSWER()+" "+answer.getText());
              if(currentQ.getANSWER().equals(answer.getText()))
              {
                  score++;
                  Log.d("score", "Your score"+score);
              }
              if(qid&lt;5){                  
                  currentQ=quesList.get(qid);
                  setQuestionView();
              }else{
                  Intent intent = new Intent(QuizActivity.this, ResultActivity.class);
                  Bundle b = new Bundle();
                  b.putInt("score", score); //Your score
                  intent.putExtras(b); //Put your score to your next Intent
                  startActivity(intent);
                  finish();
              }
          }
      });
  }
  
  private void setQuestionView()
  {
      txtQuestion.setText(currentQ.getQUESTION());
      rda.setText(currentQ.getOPTA());
      rdb.setText(currentQ.getOPTB());
      rdc.setText(currentQ.getOPTC());
      qid++;
  }
  }
  </code></pre>