title: array indexoutofbound in android in quiz app
body: <pre><code>RadioGroup rg;
  RadioButton rb1,rb2,rb3,rb4;
  Button chk,next;
  TextView que;
  public static int Marks,Correct,wrong;
  int flag = 0;
  public static String[] question={"11*11","2+5","19/1"};
  public static String[] ans={"121","7","19"};
  String[] opt={"22","131","121","1111","25","7","52","70","19","1","not Possible","0"};
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_question);
      que=(TextView)findViewById(R.id.textView1);
      chk=(Button)findViewById(R.id.button1);
      next=(Button)findViewById(R.id.button2);
      rb1=(RadioButton)findViewById(R.id.rb1);
      rb2=(RadioButton)findViewById(R.id.rb2);
      rb3=(RadioButton)findViewById(R.id.rb3);
      rb4=(RadioButton)findViewById(R.id.rb4);
      rg=(RadioGroup)findViewById(R.id.radioGroup1);
  
  
  next.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              // TODO Auto-generated method stub
              RadioButton uans =  (RadioButton)findViewById(rg.getCheckedRadioButtonId());
              String uansText = uans.getText().toString();
  
              if(uansText.equals(ans[flag]))
              {
  
                  Correct++;
              }
              else
              {
                  wrong++;
              }
              int len = que.length()-1;
              flag++;
          if(flag&lt;=len)
          {
              que.setText(question[flag]);
              rb1.setText(opt[(flag*4)]);
              rb2.setText(opt[(flag*4)+1]);
              rb3.setText(opt[(flag*4)+2]);
              rb4.setText(opt[(flag*4)+3]);
  
          }
          else {
  
              Intent in = new Intent(getApplicationContext(), Result.class);
              startActivity(in);
          }
  
  
  
          }
      });
  </code></pre>
  
  <p>I am developing a quiz app, when we press next button it will check for the correct answer and then display new questions and options and after completing all questions it will display result in new Result Activity.</p>
  
  <p>It throws an error line array indexoutofbound when we reach the last question instead of switching to Result Activity.</p>
  
  <p>help me to solve this error
  thank you in advance</p>