I have a WordFreq class that has a processLines method that creates an array from the WordCount class. I have other lines of the processLines method access WordCount without an issue.
I have:
public class WordCount{
private String word;
private int count;
public WordCount(String w){
word = w;
count = 0;
}
followed by the class methods:
public class WordFreq extends Echo {
String words, file;
String[] wordArray;
WordCount[] search;
WordFreq is passed a text file(handled in Echo) and a string of words to search for.
public WordFreq(String f, String w){
super(f);
words = w;
}
public void processLine(String line){
file = line;
wordArray = file.split(" ");
// here is where I have tried several methods to initialize the search
// array with the words in the words variable, but I can't get the
// compiler to accept any of them.
search = words.split(" ");
StringTokenizer w = new StringTokenizer(words);
search = new WordCount[words.length()];
for(int k =0; k < words.length(); k++){
search[k] = w.nextToken();
I tried a few other things that didn't work. I tried casting what was to the right of search[k] = to WordCount, but it won't get past the compiler. I keep getting incompatible types.
Required: WordCount found: java.lang.String.
I have no idea where to go from here.