All Questions
Tagged with java.util.scanner nosuchelementexception
131 questions
0
votes
0
answers
130
views
Why do I get a java.util.NoSuchElementException
I am practicing some algorithm problems. While I use Scanner to get some input, my program throws a java.util.NoSuchElementException in thread "main", and I really don't know why. It can ...
0
votes
0
answers
42
views
NoSuchElementException when using Java.Util.Scanner in console app
I am new to Java and I am doing hospital software in console app. I got a class to select options.
The exception is thrown only when option 2 is selected. I don't want the code to stop, but continuing ...
0
votes
2
answers
72
views
java.util.NoSuchElementException: no Line found from the Java Scanner
I am creating a quiz game which has one Player instance that the user can create once and then edit the username in Java. My issue comes with my use of the Scanner (I'm pretty sure) which for some ...
0
votes
1
answer
43
views
How to fix NoSuchElementException?
I have tried to load contacts from a file contacts.txt.
Issue
This program was working and now it is not.
Exception in thread "main" java.util.NoSuchElementException
at java.base/...
1
vote
0
answers
47
views
NoSuchElementException on .nextInt();
I am trying to write a program that reads the information of several user bank accounts and performs certain operations on them (withdraw, deposit, show balance) etc. The code seems to be correct, but ...
0
votes
0
answers
69
views
A NoSuchElementError
The code below is suppose to start a connect 4 game and I used the scanner class in order to get the user's input but when I run it, it gives me a NoSuchElementError.
I tried to comment out the close()...
0
votes
0
answers
60
views
Input string: Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651)
Why am i getting this error
Input string:
Exception in thread "main" java.util.NoSuchElementException: No line foundat java.base/java.util.Scanner.nextLine(Scanner.java:1651)at TMSimulator....
0
votes
1
answer
354
views
How to solve java.util.NoSuchElementException in this code?
Code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name : ");
...
-1
votes
2
answers
77
views
NoSuchElementException error for ATM Machine app (Modified)
I am currently learning Java and I am trying to retain the information I learned by building a ATM machine app (I plan on adding more to it in the future).
My current issue is I would like to ask a ...
0
votes
1
answer
48
views
how to solve NoSuchElementException Error in Scanner of Java? [duplicate]
I am making a simple console game where player is allowed to move in
x ,-x, y,-y directions according to String input collected from keyboard as a, d, w and s respectively ,
but scanner is throwing ...
0
votes
1
answer
91
views
No such element exception working with a Scanner
I am having a problem while using a Scanner and I do not know how to solve it, kind of new in Java. I have created a menu to read an input char provided by the user through a Scanner and I read ...
-1
votes
1
answer
121
views
Why am I getting NoSuchElementException for this code? Java method for giving users a second chance for correct input
I'm writing a program and have been having some trouble with my code. I invoke a method called secondChance() which gives users a second opportunity to enter a valid input. The method is defined as ...
0
votes
2
answers
394
views
Reading from the file with Scanner.useDelimiter() and hasNextLine() - NoSuchElementException
When I try to load the data from the textfile, with data like this
java;sdf;2.0;3.0;
cpp;sdks;24.6;89.0;
I'm getting the NoSuchElementException with this code.
public void loadFile() {
Scanner scan ...
1
vote
1
answer
54
views
How can I prevent java.util.Scanner from throwing NoSuchElementException when reading from System.in? [duplicate]
I'm attempting to ask the user for a double value, using Scanner.nextDouble(); but I'm getting a NoSuchElementException before I have a chance to type anything. From what I can see in the ...
2
votes
2
answers
70
views
NoSuchElementException infinite loop vs. pmd DD-anomaly
I'm kinda new to programming and very new to gradle and the pmd-plugin, so please have mercy.
If the user enters a number, scanner.nextLine() will throw a NoSuchElementException in every iteration ...
1
vote
1
answer
584
views
java No Such Element Exception when trying to get input [duplicate]
I'm trying to get user input in a loop but it crashes on the second iteration of the while. I get input once but it crashes on the second time calling getInput(), I know for a fact that the first ...
0
votes
1
answer
146
views
NoSuchElementException with ArrayList inside Method [duplicate]
I've got a class called "Player" that's supposed to
set a maximum player amount and
add player names to an ArrayList,
The class looks like this:
public class Player {
private ...
1
vote
0
answers
673
views
Junit test, NoSuchElementException by Scanner
I had one main method and i need test it. I had two test methods, if I start them separately - all worked. But if I start test all class - got error on second method.
Main method:
public boolean run() ...
-1
votes
3
answers
726
views
Java scanner input loop throwing No Such Element exception after first loop
I want a program that repeatedly prompts the user to input a number and then prints whether that number is prime or not. This works once, then on the next iteration it gives a No Such Element ...
1
vote
0
answers
540
views
Java - Getting 'Exception in thread "main" java.util.NoSuchElementException' error for Scanner
This is my code: I am trying to make a function that allows a user to return to the menu once they have finished with the program. However, I keep getting the 'NoSuchElement' error whenever I try to ...
0
votes
1
answer
168
views
NoSuchElementException with java.util.scanner in school project
I am working on a school project. I have all the functionality working, I made it on Eclipse and it runs very well but when I submit the project through Mimir which is an online tool to grade your ...
-4
votes
1
answer
314
views
Why does program with user input with Scanner in Gradle project in NetBeans showing errors?
Recently I face a strange problem in java program. I need to take user input and need to do some calculation on it. However when I am running a program with user input using Scanner class, I got same ...
0
votes
0
answers
307
views
Exception in thread "main" java.util.NoSuchElementException error with scanner
My function code is
public static void marime(ArrayList<Aplicatie> x) {
Scanner scan = new Scanner(System.in);
System.out.println("Introdu diapazonul de marime dorit ...
0
votes
1
answer
116
views
NoSuchElementException on Scanner, how do i get rid of it?
Scanner s = new Scanner(new File(filename));
while (s.hasNext())
{
if(s.next().contains(","))
{
String str= s.next().replaceAll("...
0
votes
3
answers
1k
views
Java Scanner Error : java.util.NoSuchElementException: No line found -- java.base/java.util.Scanner.nextLine(Scanner.java:1651))
I am a beginner with java and programmin over all, So this the full code for a file reader program that counts words or displays text file content, I wanted to take user inputs for commands that I ...
5
votes
5
answers
5k
views
Should a Scanner only be instantiated only once? if that's the case why so?
I know I'm going out on a limb here, but I just can't seem to understand why can't we just create an instance of the Scanner class twice. I'll add an example just in case.
import java.util.Scanner;
...
0
votes
0
answers
17
views
Java Scanner for System.in throws java.util.NoSuchElementException: No line found [duplicate]
I know there are a lot of questions about this exception on Stack Overflow but I can't find an answer or an explanation about my particular issue.
I have two functions from two different classes. The ...
0
votes
1
answer
199
views
Parking lot project error: when using a scanner. NoSuchElementException
I'll appreciate all your help.
I've been working on a course project where I have to make a parking lot that registers cars. When I use it in my IDE it works fine but when I run it through the ...
0
votes
2
answers
981
views
java.util.NoSuchElementExeption regarding the Scanner class?
The basis of this program is to have a menu that leads to various different "lessons" that need to be completed. The toMenu() method runs and returns a value back to the main method ...
0
votes
0
answers
20
views
Scanner java.util.NoSuchElementException [duplicate]
For some reason that I do not know, the switch case in my CitizenMenus method returns a NoSuchElementException. I can't seem to figure out how to fix this. I would like to be enlightened as to how I ...
0
votes
1
answer
73
views
addCruise() -- NoSuchElementException: No line found
Not to revisit old topics, but I'm working on a project for a course and I'm repeatedly encountering this error at one particular segment, where I've got various other bits of code in the same format ...
0
votes
1
answer
157
views
NoSuchElementException in nextInt() no matter what I do to the code
public class MinimumElement {
public void readIntegers(int userCount) {
int count = userCount;
int intArray[] = new int[count];
Scanner scan = new Scanner(System.in);
for (int i = 0; ...
-1
votes
1
answer
251
views
JAVA.UTIL.NoSuchElementException ERROR (SITUATION BASED)
I am having trouble with this program:
The history teacher at your school needs help grading a True/False test. The
students’ IDs and test answers are stored in a file. The first entry in the file
...
1
vote
2
answers
241
views
What may cause NoSuchElementException? [duplicate]
I spent about two hours searching for the solution but found nothing. As far as I know .nextLine() should wait for input and it usually does. But in this code, it throws java.util....
0
votes
2
answers
120
views
NoSuchElementException using Scanner
Can someone explain me, why at line 19 the compiller throws me the excpetion? I just can't figure it out... I resolve some exercises on HackerRank and i know, there are the resolves, but my code works ...
-1
votes
2
answers
224
views
Why my Java program works perfectly in windows but it's a disaster in linux?
I wrote a program that reads a text file, deletes the requested string and rewrites it without the string. This program takes three arguments from the terminal: 1) the input file 2) the string 3) the ...
0
votes
1
answer
108
views
Exception in thread "main" java.util.NoSuchElementException while getting unknown number of inputs and then getting another input
I'm getting an unknown number of inputs in an array initially using hasNext() and the getting another set of inputs but getting NoSuchElementException.
Code snippet:
public class Hello {
...
0
votes
2
answers
1k
views
How do I fix a NoSuchElementException from a input file?
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 ...
0
votes
2
answers
328
views
'Exception in thread "main" java.util.NoSuchElementException: No line found' When iterating through a loop reading a file
Java noob here. So I'm writing a program that reads data from a text file, and stores the data into an array of objects. Each iteration of the loops reads 4 pieces of data (a name (string), and 3 ...
0
votes
1
answer
55
views
Scanner is creating a NoSuchElementException error, and I can't figure out why
I was given the assignment to make a table of hurricanes over the Atlantic, and their wind speed, pressure, etc. and I was testing it to make sure that the scanner inFile was working but kept getting ...
3
votes
1
answer
121
views
handle Exceptions casued by input scanner
I'm trying to do encode/decode program and I'm encountering all kinds of Exceptions here!
problems that is popping up caused by multiple/single scanner/s:
InputMismatchException | ...
1
vote
1
answer
2k
views
Why cant I just create another scanner object after using scanner.close()?
After using the scanner.close() method, I cannot open another scanner. I have searched my question on google to only find people giving a solution for a workaround. I just want to understand why this ...
1
vote
0
answers
29
views
I am trying to read a file from a scanner that is (age, name) and keep getting errors [duplicate]
I have asked a question like this before but am now getting a new error.
I am trying to take a file of ages and names (age, name) that the user put in through the console and sort them in ascending ...
0
votes
1
answer
50
views
Why does this skip over the user_input section of this code if the user inputs an invalid selection?
The getSelection method allows the user to input a number in reference to a command list. If the user enters a valid number the code runs flawlessly. How ever if the user enters an invalid number the ...
0
votes
3
answers
394
views
Scanner.hasNext() returns false when compiled online but true when compiled on eclipse [duplicate]
I'm trying to solve a competitive coding problem and it works fine when i execute it on eclipse or on the command prompt, but when i uploaded the solution on the website it didn't execute and threw ...
0
votes
1
answer
42
views
how could I create a Scanner object again after I have executed its close() method?
when I inputed secondly it thorowed java.util.NoSuchElementException, if I want to use Scanner again after I close the sc, how should I do?
Another question: How do I close an Scanner object created ...
0
votes
1
answer
52
views
Not waiting for scanner input, throwing ElementNotFoundException
So I'm trying to write a simple menu, where a few options are printed to the screen and then I ask the user for which option they want. Whatever they type should get saved and send them to one of the ...
0
votes
1
answer
2k
views
What's the best way to read input in Java, especially for consecutive strings? I don't know when to use next() and nextLine()
I'm getting this error in a really simple code and I am not able to figure it out.
Also, please suggest what is the best way to read two consecutive strings, like in this case. I face ...
-1
votes
1
answer
106
views
Why do I have this java.util.NoSuchElementException?
If I call a class member using Scanner, and if I had used Scanner before in the main method, I get the NoSuchElementException error even though all the inputs are available.
import java.util.Scanner;
...