title: error in percolation program: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
body: <p>Hello I encountered this error while trying to run this program and I cannot figure out what's wrong with it:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at PercolationStats.main </p>
  </blockquote>
  
  <p>and here is the code:</p>
  
  <pre><code>/****************************************************************
    * Compilation:  javac PercolationStats.java
    * Execution:    java PercolationStats N T
    * Dependencies: Percolation.java, StdStats.java, StdRandom.java,
    *               StdOut.java
    * 
    * % java PercolationStats 20 1000
    *      mean                    = 0.591100
    *      stddev                  = 0.046068
    *      95% confidence interval = 0.582071, 0.600129
    * 
    * % java PercolationStats 200 100
    *      mean                    = 0.593257
    *      stddev                  = 0.016242
    *      95% confidence interval = 0.592251, 0.594264
    * 
    ***************************************************************/
  
  public class PercolationStats { 
  
      private int experimentsCount; 
      private Percolation pr; 
      private double[] fractions; 
  
      public PercolationStats(int N, int T) { 
          if (N &lt;= 0 || T &lt;= 0) { 
              throw new IllegalArgumentException("Given N &lt;= 0 || T &lt;= 0"); 
          } 
  
          experimentsCount = T; 
          fractions = new double[experimentsCount]; 
          for (int expNum = 0; expNum &lt; experimentsCount; expNum++) { 
              pr = new Percolation(N); 
              int openedSites = 0; 
              while (!pr.percolates()) { 
                int i = StdRandom.uniform(1, N + 1); 
                  int j = StdRandom.uniform(1, N + 1); 
                  if (!pr.isOpen(i, j)) { 
                      pr.open(i, j); 
                      openedSites++; 
                  } 
              } 
              double fraction = (double) openedSites / (N * N); 
              fractions[expNum] = fraction; 
          } 
      } 
  
      public double mean() { 
          return StdStats.mean(fractions); 
      } 
  
      public double stddev() { 
          return StdStats.stddev(fractions); 
      } 
  
      public double confidenceLo() { 
          return mean() - ((1.96 * stddev()) / Math.sqrt(experimentsCount)); 
      } 
  
      public double confidenceHi() { 
          return mean() + ((1.96 * stddev()) / Math.sqrt(experimentsCount)); 
      } 
  
      public static void main(String[] args) { 
          int N = Integer.parseInt(args[0]); 
          int T = Integer.parseInt(args[1]); 
          PercolationStats ps = new PercolationStats(N, T); 
          String confidence = ps.confidenceLo() + ", " + ps.confidenceHi(); 
          StdOut.println("mean                    = " + ps.mean()); 
          StdOut.println("stddev                  = " + ps.stddev()); 
          StdOut.println("95% confidence interval = " + confidence); 
      } 
  }
  </code></pre>