title: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
body: <p>I always get this error whenever i compile the code: </p>
  
  <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0</p>
  
  <p>I know that the error is in the array chosen[], but i think I initializated it correctly. Can anyone tell where the problem is? </p>
  
  <pre><code> public  boolean[] chosen=new boolean[n];
  
   public void clear() {
       for (int k= 0; k &lt; n; k++)
       {
      chosen[k] = false;
  
       }
  </code></pre>
  
  <p>I saw other answers on the same question , but none of them was helpful.
  Thank you.</p>