Im getting a syntax error with the semi at the end of my array and the last closing bracket. I've been banging my head over this for a bit. Does anyone have any ideas on how to resolve this?
public class arrayWords {
private Words wl;
private String gamewords[];
public arrayWords() {
wl = new Words();
gamewords = new String[] { "dog", "cat", "coffee", "tag", "godzilla", "gamera", "lightning", "flash",
"spoon", "steak", "moonshine" };
setArray();
}
public void setArray() {
for (int i = 0; i < gamewords.length; i++)
wl.wordList[i].setWord(gamewords[i]);
}
}
public class Words {
public Word wordList[];
public Words() {
super();
wordList = new Word[25];
for (int i = 0; i < 24; i++) {
wordList[24] = new Word();
}
}
}
public class Word {
String name;
Words word = new Words();
public Word() {
super();
name = new String("");
}
public Word(String w) {
super();
name = new String(w);
}
public String getWord() {
return name;
}
public void setWord(String s) {
this.name = new String(s);
}
}
public class wordTest {
public static void main(String args[]) {
Words wl = new Words();
arrayWords newArray = new arrayWords();
newArray.setArray();
for (int i = 0; i < 25; i++)
System.out.println(wl.wordList[i].getWord());
}
}
forloop in a methodfor (int i = 0; i < 24; i++) { wordList[24] = new Word(); }probably isn't doing what you want it to do. Perhapsi < 25andwordList[i] = ....Wordconstructs aWordListwhen it is constructed which then constructs 25Words so either class's constructor will blow out the stack.