我的問題是我無法從帶有單詞列表的.txt向數組賦值。我相信問題在於我要求的東西還不可用,比如在未知的情況下要求未來的某些東西。這是我的代碼,任何幫助將與任何提示將被讚賞。Java將值賦給增加數組
File words = new File("wordList.txt"); //document with words
String wordToArray = new String();
String[] arrWord = new String[3863]; // number of lines
Scanner sc = new Scanner(words);
Random rWord = new Random();
int i = 0;
do
{
wordToArray = sc.next(); //next word
arrWord[i] = wordToArray; //set word to position
i++; //move to next cell of the array
sc.nextLine(); //Error occurs here
}while(sc.hasNext());
添加您正在收到的特定錯誤。這段代碼不起作用? – markbernard 2015-02-24 20:09:20
NoSuchElementException:找不到行 – NoviceCoder 2015-02-24 20:10:06
堆棧跟蹤應該有一個指向您的代碼的行號。上面代碼中的哪一行?你必須使用數組嗎? ArrayList將爲您提供幾乎無限的容量。 – markbernard 2015-02-24 20:12:01