I got an run time exception in my program while I am reading a file through a Scanner.
java.util.NoSuchElementException: No line found at java.util
with Scanner you need to check if there is a next line with hasNextLine()
Scanner
hasNextLine()
so the loop becomes
while(sc.hasNextLine()){ str=sc.nextLine(); //... }
it's readers that return null on EOF
EOF
ofcourse in this piece of code this is dependent on whether the input is properly formatted