title: Error: Main method not found in class Binary, please define the main method as: public static void main(String[] args)
body: <p>When I exercised an example code of Algorithms(by Sedgewick), I tried to run that. The execution in Eclipse failed with following error message:
  <em>Error: Main method not found in class Binary, please define the main method as: 
  public static void main(String[] args)</em> </p>
  
  <p>The DrJava shows:</p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 0
      at BinarySearch.main(BinarySearch.java:61)
  </code></pre>
  
  <p>I think there must be something wrong with this line <code>In in = new In(args[0]);</code>. </p>
  
  <p>The source code is :</p>
  
  <pre><code>import java.util.Arrays;
  
  public class BinarySearch {
  
      public static int rank(int key, int[] a) {
          int lo = 0;
          int hi = a.length - 1;
          while (lo &lt;= hi) {
              // Key is in a[lo..hi] or not present.
              int mid = lo + (hi - lo) / 2;
              if      (key &lt; a[mid]) hi = mid - 1;
              else if (key &gt; a[mid]) lo = mid + 1;
              else return mid;
          }
          return -1;
      }
  
  
      public static void main(String[] args) {
  
          // read in the integers from a file
          In in = new In(args[0]); 
          int[] whitelist = in.readAllInts();
  
          // sort the array
          Arrays.sort(whitelist);
  
          // read key; print if not in whitelist
          while (!StdIn.isEmpty()) {
              int key = StdIn.readInt();
              if (rank(key, whitelist) == -1)
                  StdOut.println(key);
          }
      }
  }
  </code></pre>
  
  <p>PS: "In","StdOut",and "StdIn" are three external libraries, and have been imported successful. 
  and the line 61 in the first error display is this line " In in = new In(args[0]); "</p>
  
  <p>The part defined in.readAllInts() is following:</p>
  
  <pre><code>/**
   * Read all ints until the end of input is reached, and return them.
   */
  public int[] readAllInts() {
      String[] fields = readAllStrings();
      int[] vals = new int[fields.length];
      for (int i = 0; i &lt; fields.length; i++)
          vals[i] = Integer.parseInt(fields[i]);
      return vals;
  }
  </code></pre>