• Register
0 votes
803 views

Problem :

I am getting the run time exception in my program while I am reading a file through a Scanner.
exception in thread "main" java.util.nosuchelementexception: no line found
6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

To resolve the issue with Scanner you need to check if there is a next line with hasNextLine()

so the loop becomes

while(sc.hasNextLine()){
    str=sc.nextLine();
    
}

Further Readings:

https://github.com/gradle/gradle/issues/3350

9 7 4
38,600 points

Related questions

0 votes
1 answer 636 views
636 views
Problem : I am just a beginner in java coding. Recently i got this error and was unable to solve it. Please help me with this. exception in thread "main" java.lang.illegalstateexception: scanner closed
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 8 views
8 views
Problem: Please solve it … Because I am unable to find out the solution
asked Mar 14 Ifra 24.4k points
0 votes
1 answer 2 views
2 views
Problem: Scanner input = new Scanner(System.in); Could you give me a detailed explanation on what the code above is doing step by step? I don't really understand how it works
asked Mar 27 ummesalma 25.2k points
0 votes
1 answer 5 views
5 views
Problem: when I run the following code it shows an error that the scanner cannot be resolved to type. I checked that JRE is installed and the version is 1.7 what else do I need to check? please help.
asked Mar 27 ummesalma 25.2k points
0 votes
1 answer 23 views
23 views
I've gone through the error reports. Please help.
asked Dec 17, 2020 TeamScript 13.5k points
0 votes
1 answer 5 views
5 views
Problem: Hello! I do not have a lot of knowledge about Java and I keep trying random stuff that I find on the web. I saw following program somewhere: import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] ... .util.HashMap$KeyIterator.next(HashMap.java:1469) at Main.main(Main.java:13) Please explain why this exception is being thrown by this program.
asked Mar 31 Code Learner 9.2k points
0 votes
1 answer 60 views
0 votes
1 answer 33 views
33 views
I can't see any errors and as I said, I've run this code before.
asked Jan 24 TeamScript 13.5k points
0 votes
1 answer 15 views
15 views
Problem: exception in thread "main" java.util.inputmismatchexception
asked Feb 23 Hira 2.2k points
0 votes
1 answer 7 views
7 views
Problem: This is a feature of NoSuchMethodError in Java and complains about "main" which is the name of the method that JVM tries to connect to but doesn't find in the wrong class. java.lang.NoSuchMethodError
asked Feb 7 ahmedadel9090 3.1k points