我的问题是我无法从带有单词列表的.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