Question: I have a method that returns a scanner to a text file that has lines of input (I can't get this to display properly, but like - Hi (new line) This (\n) Is (\n) Me (\n)). Then in main, I used the scanner to count the number of lines of input there are, and then resetted the scanner. I later used the scanner to put the lines of input into an array (I don't want an ArrayList), but Java says "java.util.NoSuchElementException: No line found"...

```
while(scanner.hasNextLine()){
    numOfStrings++;
    scanner.nextLine();
}

scanner.reset();
String[] stringsOfInput = new String[numOfStrings];
for(int i = 0; i < numOfStrings; i++){
    String s = scanner.nextLine();   //returns "No line found" error message
    stringsOfInput[i] = s;
}

```

Does anyone know how to fix this so it does what it should?

Answer: 
The most versatile way to do this would be to add the lines into an `ArrayList<String>` then make that into an Array(`String[] stringsOfInput = myArrayList.toArray(new String[myArrayList.size()]);`)
You may want to try putting the content of the for loop within the while. That way you can get the number of strings and each string in one loop through the file.

EDIT:
Sample with ArrayList

```
ArrayList<String> stringsOfInput = new ArrayList<String>();

while(scanner.hasNextLine())
{
    stringsOfInput.add(scanner.nextLine());
    numOfStrings++;
}

```