Enhanced for loop issue
<p>I have an assignment where I have to make a file I/O program. It must open a text file that has a random word every line. Print out the text file in the run box below. Make an array with each word in a different array. </p>

<p>Also, I have to be able to search the array for certain words, or search words that have letter combinations. I keep getting an error for my enhanced for loop when searching for a word, please help</p>

<p>Here is my code:  </p>

<pre><code>import java.io.*;
import java.util.*;
import javax.swing.*;

class tester {
    private Scanner x;
    private Scanner wok;
    Scanner scan = new Scanner(System.in);
    String[] array;
    String delimiter = "\n";
    int num = 0;

    // ***************************************************************
    public void openFile() {
        try {
            x = new Scanner(new File("D:\\PRAGI\\randomwords.txt"));
            wok = new Scanner(new File("D:\\PRAGI\\randomwords.txt"));

            // x = new Scanner (file);
        } catch (Exception e) {
            System.out.println("Could not find file");
        }
    }

    // *****************************************************************
    public void readFile() {
        int count = 0;
        try {
            while (x.hasNext()) {
                String a = x.next();
                count++;
                String[] array = a.split("\n");

                for (int i = 0; i &lt; array.length; i++) {
                    System.out.println(array[i]);
                }
            }
            System.out.println("Number of lines: " + count);
        } catch (Exception e) {
            System.out.println("Woops, encountered a problem");
            System.exit(0);
        }

        System.out.println("What word would you like to search for?");
        String word = scan.nextLine();

        for (String w : array) {
            if (w.contains(word))
                ;
            {
                System.out.println("Found " + word);
            }
        }
    }

    // ******************************************************************
    public void closeFile() {
        x.close();
    }

    public static void main(String[] args) {
        tester r = new tester();

        r.openFile();
        r.readFile();
        // r.searchFile();
        r.closeFile();

    }

}








//****************************************************************** 
public void closeFile()
{
 x.close();
}
 public static void main(String[]args)
 {
  tester r = new tester();

  r.openFile();
  r.readFile();
  //r.searchFile();
  r.closeFile();

  }

}








//****************************************************************** 
public void closeFile()
{
 x.close();
}
 public static void main(String[]args)
 {
  tester r = new tester();

  r.openFile();
  r.readFile();
  //r.searchFile();
  r.closeFile();

  }

}
</code></pre>
