0
因此,我一直在Java中編寫一個項目,並嘗試將數組列表引用到另一個類時遇到了暫停。第一個代碼是我試圖引用ArrayList
的類。第二個是我創建ArrayList
的地方。將Java文件轉換爲ArrayList並將ArrayList引用到另一個類
import Game.App;
public class WordPuzzleGenerator {
public WordPuzzleGenerator() {
if (Game.SizeOfPuzzle.currentRows == 4){
threeLetterWordList
}else if (Game.SizeOfPuzzle.currentRows == 5){
maximum = 12482;
}else{
maximum = 1310;
}
}
Scanner threeLetterScanner = new Scanner(File("3LetterWords.txt"));
ArrayList<String> threeLetterWordList = new ArrayList<String>();
while (threeLetterScanner.hasNext()){
threeLetterWordList.add(threeLetterScanner.next());
}
threeLetterScanner.close();
Scanner fourLetterScanner = new Scanner(File("4LetterWords.txt"));
ArrayList<String> fourLetterWordList = new ArrayList<String>();
while (fourLetterScanner.hasNext()){
fourLetterWordList.add(fourLetterScanner.next());
}
fourLetterScanner.close();
Scanner fiveLetterScanner = new Scanner(File("5LetterWords.txt"));
ArrayList<String> fiveLetterWordList = new ArrayList<String>();
while (fiveLetterScanner.hasNext()){
fiveLetterWordList.add(fiveLetterScanner.next());
}
fiveLetterScanner.close();
}
如果我理解得很好,你必須使用getters。 – Drumnbass
那到底是什麼問題? – Mureinik
@Mureinik正如wordPuzzleGenerator類所示,我試圖引用已經在App中創建的ArrayList的第一個if語句。 – Jackson