I was wondering if anyone could help solve this NoSuchElements exception in my program which scans a text very large text and then is added to the ArrayList.
I have tried re-arranging the order of the code to see if that would fix it but now I don't know how to fix it.
Exception itself:
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1478)
at mainTest.main(mainTest.java:11)
mainTest class:
import java.io.*;
import java.util.*;
public class mainTest {
public static void main(String args[]) throws FileNotFoundException {
ArrayList<String> bigBoi = new ArrayList<>(500000);
Scanner scan1 = new Scanner(new File("LargeDataSet.txt"));
while (scan1.hasNextLine()) {
scan1.next();
String data = scan1.next() + " " + scan1.next();
bigBoi.add(data);
}
ArrayList<String> successful = new ArrayList<>(500000);
}
}
The unit of a .txt file : https://drive.google.com/file/d/1MWfMKMhSvuopOt9WwquABgYBTt0M4eLA/view?usp=sharing
(sorry for needing you to download it from a google drive, the file is so long I probably would've been reported or something if I had pasted 500,000 lines)