title: Caused by: java.lang.ArrayIndexOutOfBoundsException: length=8; index=8
body: <p>hi dear here I am posting my whole class where I am getting problem. First I explain my problem. I am generating an arrayList "Items" using spinners and the elements in spinners and arrays are exactly same then After comparing array length and ArayList size I want to jump on next activity but problem is occoured in comparing arrays now please help me for this problem
  Thanks here is my activity</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>package com.example.mine4.pantryrecipes;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import java.util.List;
  import java.util.ArrayList;
  
  import android.view.View;
  import android.widget.Toast;
  import android.widget.Button;
  import android.widget.TextView;
  
  
  
  public class AddItem extends Activity {
      MultiSelectionSpinner spinner1,spinner2,spinner3,spinner4;
      Button button1;
      TextView tv;
      private int count = 0;
      List&lt;String&gt; Items=new ArrayList&lt;&gt;();
      List&lt;String&gt; veg=new ArrayList&lt;&gt;();
      List&lt;String&gt; spice=new ArrayList&lt;&gt;();
      List&lt;String&gt; dairy=new ArrayList&lt;&gt;();
      ArrayList&lt;Boolean&gt; subset = new ArrayList&lt;&gt;();
      String[] arrayRecipe = { "chicken","vegetable oil","ginger",
              "onion", "garlic","potatoes","tomatoes","roasted peanuts", "peanut butter"};
      String[] arrayRecipe2 = { "chicken","garlic","vegetable oil", "tomatoes",
              "Dijon mustard","breadcrumbs","Parmesan cheese","unsalted butter"};
      String[] arrayRecipe3 = { "chicken", "vegetable oil","unsalted butter",
              "sugar", "garlic", "sauce"};
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_add_item);
          button1=(Button)findViewById(R.id.button1);
          tv=(TextView)findViewById(R.id.tv);
          String[] arrayItems = {"chicken"};
          String[] arrayVeg = { "vegetable oil", "ginger",
                  "garlic","potatoes" ,"tomatoes","onion"};
          String[] arraySpice = { "roasted peanuts", "sauce","Dijon mustard" };
          String[] arrayDairy = { "breadcrumbs", "Parmesan cheese", "unsalted butter","sugar", "peanut butter" };
          spinner1 = (MultiSelectionSpinner) findViewById(R.id.mySpinner1);
          spinner2 = (MultiSelectionSpinner) findViewById(R.id.mySpinner2);
          spinner3 = (MultiSelectionSpinner) findViewById(R.id.mySpinner3);
          spinner4= (MultiSelectionSpinner) findViewById(R.id.mySpinner4);
  
          spinner1.setItems(arrayItems);
          spinner2.setItems(arrayVeg);
          spinner3.setItems(arraySpice);
          spinner4.setItems(arrayDairy);
  
      }
      public void onClick(View v)
      {
          Items=spinner1.getSelectedStrings();
          veg=spinner2.getSelectedStrings();
          spice=spinner3.getSelectedStrings();
          dairy=spinner4.getSelectedStrings();
          Items.addAll(veg);
          Items.addAll(spice);
          Items.addAll(dairy);
  //        for(int i=0;i&lt;Items.size();i++)
  //            tv.append(Items.get(i));
  
          compareArray();
          //count++;
      }
      public void compareArray()
      {
          for(int j = 0 ; j &lt; arrayRecipe.length ; j++)
              {
                  for(int i = 0 ; i &lt;Items.size() ; i++)
                  {
                      if((arrayRecipe[i].equals(Items.get(j))))
                      {
                          subset.add(true);
                          break;
                      }
                      if ((arrayRecipe2[i].equals(Items.get(j))))
                      {
                          subset.add(true);
                          break;
                      }
                      if ((arrayRecipe3[i].equals(Items.get(j))))
                      {
                          subset.add(true);
                          break;
                      }
                  }
              }
  
          if(subset != null) {
              if ((arrayRecipe.length == subset.size())) {
                  Intent nextClass = new Intent();
                  nextClass.setClass(AddItem.this, TenIngreRec.class);
                  startActivity(nextClass);
                  finish();
                  Toast.makeText(getApplicationContext(), "arrayRecipe", Toast.LENGTH_LONG).show();
              }
              if ((arrayRecipe2.length == subset.size())) {
                  Intent nextClass = new Intent();
                  nextClass.setClass(AddItem.this, EightIngreRec.class);
                  startActivity(nextClass);
                  finish();
                  Toast.makeText(getApplicationContext(), "arrayRecipe2", Toast.LENGTH_LONG).show();
              }
              if ((arrayRecipe3.length == subset.size())) {
                  Intent nextClass = new Intent();
                  nextClass.setClass(AddItem.this, EightIngreRec.class);
                  startActivity(nextClass);
                  finish();
                  Toast.makeText(getApplicationContext(), "arrayRecipe3", Toast.LENGTH_LONG).show();
              }
              else {
                  Toast.makeText(getApplicationContext(), "Un-Matched", Toast.LENGTH_LONG).show();
              }
          }
      }
      @Override
      public void onBackPressed()
      {
          // code here to show dialog
          super.onBackPressed();  // optional depending on your needs
          Intent intn = new Intent(AddItem.this,Exmain.class);
          startActivity(intn);
      }
    
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>and the major problem occured in this code which is array indexOutOfBound</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> for(int j = 0 ; j &lt; arrayRecipe.length ; j++)
              {
                  for(int i = 0 ; i &lt;Items.size() ; i++)
                  {
                      if((arrayRecipe[i].equals(Items.get(j))))
                      {
                          subset.add(true);
                          break;
                      }
                      if ((arrayRecipe2[i].equals(Items.get(j))))
                      {
                          subset.add(true);
                          break;
                      }
                      if ((arrayRecipe3[i].equals(Items.get(j))))
                      {
                          subset.add(true);
                          break;
                      }
                  }
              }</code></pre>
  </div>
  </div>
  </p>
  
  <p>thanks again for helping me </p>