title: Why am I getting this IndexOutofBoundsexception?
body: <pre><code>package org.example.mbtiapplication;
  
  import java.util.ArrayList;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemSelectedListener;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.Spinner;
  import android.widget.TextView;
  
  public class MBTITest extends Activity implements OnItemSelectedListener   {
  
      int I, E, N, S, T, F, J, P;
      String[] type;
      ArrayList&lt;String&gt; Evaluator = new ArrayList&lt;String&gt;(4);
      Spinner firstSpinner ;
      Spinner secondSpinner ;
      Spinner thirdSpinner;
      Spinner fourthSpinner ;
  
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_mbtitest);
          firstSpinner = (Spinner) findViewById(R.id.spinner1);
          secondSpinner = (Spinner) findViewById(R.id.spinner2);
          thirdSpinner = (Spinner) findViewById(R.id.spinner3);
          fourthSpinner = (Spinner) findViewById(R.id.spinner4);
          type = new String[3];
          addItemsOnSpinner1();
          addItemsOnSpinner2();
          addItemsOnSpinner3();
          addItemsOnSpinner4();
          final Button calculate = (Button) findViewById(R.id.calculate);
          calculate.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  getPersonality();
                  evaluateType();
                  TextView calculatedPersonality = (TextView) findViewById(R.id.personalitytype);
                  calculatedPersonality.setText(type.toString());
  
              }
          });
  
  
          }
  
      public void addItemsOnSpinner1(){   
          Spinner firstSpinner = (Spinner) findViewById(R.id.spinner1);
          // Create an ArrayAdapter using the string array and a default spinner layout
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this,
                  R.array.spinnerarraybool, android.R.layout.simple_spinner_item);
          // Specify the layout to use when the list of choices appears
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          // Apply the adapter to the spinner
          firstSpinner.setAdapter(adapter);
  
  
      }
  
      public void addItemsOnSpinner2(){   
          Spinner firstSpinner = (Spinner) findViewById(R.id.spinner2);
          // Create an ArrayAdapter using the string array and a default spinner layout
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this,
                  R.array.spinnerarraybool, android.R.layout.simple_spinner_item);
          // Specify the layout to use when the list of choices appears
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          // Apply the adapter to the spinner
          firstSpinner.setAdapter(adapter);
      }
  
      public void addItemsOnSpinner3(){   
          Spinner firstSpinner = (Spinner) findViewById(R.id.spinner3);
          // Create an ArrayAdapter using the string array and a default spinner layout
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this,
                  R.array.spinnerarraybool, android.R.layout.simple_spinner_item);
          // Specify the layout to use when the list of choices appears
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          // Apply the adapter to the spinner
          firstSpinner.setAdapter(adapter);
      }
  
      public void addItemsOnSpinner4(){   
          Spinner firstSpinner = (Spinner) findViewById(R.id.spinner4);
          // Create an ArrayAdapter using the string array and a default spinner layout
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this,
                  R.array.spinnerarraybool, android.R.layout.simple_spinner_item);
          // Specify the layout to use when the list of choices appears
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          // Apply the adapter to the spinner
          firstSpinner.setAdapter(adapter);
      }
  
  
  
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View arg1, int arg2,
              long arg3) {
          switch (arg1.getId()){
          case R.id.spinner1:
              String firstAnswer = firstSpinner.getSelectedItem().toString();
              Evaluator.remove(0);
              Evaluator.add(0 ,firstAnswer);
              break;
          case R.id.spinner2:
              String secondAnswer = firstSpinner.getSelectedItem().toString();
              Evaluator.remove(1);
              Evaluator.add(1, secondAnswer);
              break;
          case R.id.spinner3:
              String thirdAnswer = firstSpinner.getSelectedItem().toString();
              Evaluator.remove(2);
              Evaluator.add(2, thirdAnswer);
              break;
          case R.id.spinner4:
              String fourthAnswer = firstSpinner.getSelectedItem().toString();
              Evaluator.remove(3);
              Evaluator.add(3, fourthAnswer);
              break;
          }
  
  
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
          // TODO Auto-generated method stub
  
      }
  
  
      //Evaluates answers 
      public void getPersonality(){
          if (Evaluator.get(0) == "True"){
              E += 1;
          }
          if (Evaluator.get(0) == "In the Middle"){
              E += 1;
              I += 1;
          }
          if (Evaluator.get(0) == "False"){
              I += 1;
          }
  
  
          if (Evaluator.get(1) == "True"){
              N += 1;
          }
          if (Evaluator.get(1) == "In the Middle"){
              N += 1;
              S += 1;
          }
          if (Evaluator.get(1) == "False"){
              S += 1;
          }
  
  
          if (Evaluator.get(2) == "True"){
              F += 1;
          }
          if (Evaluator.get(2) == "In the Middle"){
              F += 1;
              T += 1;
          }
          if (Evaluator.get(2) == "False"){
              T += 1;
          }
  
  
          if (Evaluator.get(3) == "True"){
              P += 1;
          }
          if (Evaluator.get(3) == "In the Middle"){
              P += 1;
              J += 1;
          }
          if (Evaluator.get(3) == "False"){
              J += 1;
          }
  
      }
  
      public void evaluateType(){
          //INTRO VS EXTRO
          if (E &gt; I){
              type[0] = "E";  
          }
          if (I &gt; E){
              type[0] = "I";
          }
          if (I == E){
              type[0] = "x";      
          }
          //INTUITION VS SENSING
          if (N &gt; S){
              type[1] = "N";  
          }
          if (S &gt; N){
              type[1] = "S";
          }
          if (S == N){
              type[1] = "x";      
          }
          //THINKING VS FEELING
          if (T &gt; F){
              type[2] = "T";  
          }
          if (F &gt; T){
              type[2] = "F";
          }
          if (T == F){
              type[2] = "x";      
          }
          //JUDGING VS PERCIEVING
          if (J &gt; P){
              type[3] = "J";  
          }
          if (P &gt; J){
              type[3] = "P";
          }
          if (P == J){
              type[3] = "x";      
          }
  
      }
  
  
  
  
  
  
  
  
  
  
  
  }
  
  11-25 16:55:22.154: E/AndroidRuntime(1840): FATAL EXCEPTION: main
  11-25 16:55:22.154: E/AndroidRuntime(1840): Process: org.example.mbtiapplication, PID: 1840
  11-25 16:55:22.154: E/AndroidRuntime(1840): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at java.util.ArrayList.get(ArrayList.java:308)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at org.example.mbtiapplication.MBTITest.getPersonality(MBTITest.java:136)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at org.example.mbtiapplication.MBTITest$1.onClick(MBTITest.java:43)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at android.view.View.performClick(View.java:4424)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at android.view.View$PerformClick.run(View.java:18383)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at android.os.Handler.handleCallback(Handler.java:733)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at android.os.Handler.dispatchMessage(Handler.java:95)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at android.os.Looper.loop(Looper.java:137)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at android.app.ActivityThread.main(ActivityThread.java:4998)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at java.lang.reflect.Method.invokeNative(Native Method)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at java.lang.reflect.Method.invoke(Method.java:515)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
  11-25 16:55:22.154: E/AndroidRuntime(1840):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Sorry for the nooby question.  I am a beginner programmer and have ran into another exception.  I have tried to mess with my ArrayList code and method .get() but to no avail I am here again.  This happens when I click on my button 'calculate.'  Any theories?</p>