title: Java: Array Index Out of Bounds
body: <p>I get this exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100
  at Vindu.&lt;init&gt;(setevelger.java:64)
  at setevelger.main(setevelger.java:22)
  </code></pre>
  
  <p>when I'm running this code:</p>
  
  <pre><code>    public knapp seter[]=new knapp[100]; //knapp means button
  
      int rad=0; //rows
      int sete=0; //seats     
      int antallSeter=0; //number of seats
      for (int i=0;i&lt;10;i++){
          for (int j=0;j&lt;10;j++){
              seter[antallSeter]= new knapp("Rad "+(rad+1)+", Sete "+(sete+1));
              seter[antallSeter].setBackground(Color.GREEN);
  
              add(seter[antallSeter]); 
              antallSeter++;              
              if(j==10){
                  sete=0;
                  }else{              
                      sete++; 
                      }           
              }
          rad++;
          }   
  
      //creates an eventlistener
      Knappelytter lytteren = new Knappelytter();
      seter[antallSeter].addActionListener(lytteren);
      pack();     
  </code></pre>
  
  <p>and if I do this:</p>
  
  <pre><code>public knapp seter[]=new knapp[120]; //knapp means button
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  at Vindu.&lt;init&gt;(setevelger.java:64)
  at setevelger.main(setevelger.java:22)
  </code></pre>
  
  <p>both errors come at runtime when the window is being created.</p>
  
  <p>So, the code is supposed to create 100 buttons and store them in an array, and each button is to have a row and seat number.</p>
  
  <p>I'm stuck, I have no idea where to look anymore..</p>
  
  <p>Should I perhaps use an arraylist?</p>