Questions tagged [nosuchelementexception]

Use this tag if your problem is caused by or primarily involves a NoSuchElementException in Java.

The NoSuchElementException is a RuntimeException thrown by the nextElement method of an Enumeration to indicate that there are no more elements in the enumeration.

It is also thrown by:

  • the various next* methods (nextInt, nextFloat, nextLine,...) of the Scanner class when input is exhausted;
  • the get method of the Java 8 Optional class when a value is not present;
  • the methods firstElement and lastElement in the Vector class when there are no elements;
  • the methods firstKey and lastKey in the TreeMap class when there are no keys;
  • the methods getFirst, getLast, removeFirst and removeLast in LinkedList when there are no elements;

and other collections.

573 questions
-2
votes
1 answer

How java.util.NoSuchElementException (basic program)

java.util.NoSuchElementException problem... I used two scanners scanbud() and scabudrad()
-2
votes
1 answer

Exception in thread "main" java.util.NoSuchElementException can't find a solution to my case

I have looked everyone where a reasonable explanation as to how I can fix the problem. Can someone look at my code and give me some suggestions. Here is my code: import java.util.Scanner; public class ShoppingCartManager { public static void…
-2
votes
1 answer

How to fix NoSuchElementExeption in Java

I've made a simple game with 2 classes. It uses a scanner and when I try it it says java.util.NoSuchElementExeption. It also says the errors are on row 19 in RNGlog and 24 in RNG. Please help First class: RNG public class RNG { public static void…
DivaKill
  • 67
  • 6
-2
votes
2 answers

How do I catch a NoSuchElementException?

I am making a function that returns a Boolean type of whether a String has enough tokens. I do this by using this code: public boolean isEnoughTokens(int tokens, String problem) { try { StringTokenizer token = new…
TheLittleCoder
  • 21
  • 2
  • 11
-2
votes
1 answer

NoSuchElementException using Scanner and System.in

Im making a program to read every user's input response inside a while loop to check if that year is a leap year or not. When I run it, the console tells me: Exception in thread "main" java.util.NoSuchElementException What does that mean and how…
solorzke
  • 43
  • 1
  • 4
-2
votes
2 answers

No Such Element Exception. I'm stuck

Code: package FisherTCh5Sec4to5; import java.util.Scanner; public class FisherTCh5Sec4to5 { public static int generateRandomInt(int lowerLimit, int upperLimit){ int range = (upperLimit - lowerLimit) + 1; int randomInt = (int)…
fishertrav
  • 11
  • 2
-2
votes
1 answer

Concerning NoSuchElementException

I've been working on a program that is supposed to analyze a credit card number that the user enters in, including info regarding its company, whether it is valid or not, and so on. My issue is that I continue to run the NoSuchElementException, and…
-3
votes
4 answers

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"username"} while sending text to username

Need help in solving below error : URL : https://services.gst.gov.in/services/login username = driver.find_element_by_name("username"); File…
-3
votes
1 answer

NoSuchElement exception error in particular program

I have used Scanner for all my programming needs, but for some reason, I'm unable to get through this error: Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at …
Musicjay
  • 1
  • 3
-3
votes
3 answers

trying to print out the array in java

System.out.println("Please input the elements and seperate each by a comma."); e = dk.nextLine(); String[] elems = new String[e.length()]; st = new StringTokenizer(e,","); for (int i = 0; i
7Kei
  • 25
  • 1
-3
votes
1 answer

Catch block is not getting executed

pls find the code below: public static void selectDefinition(String defName) { driver.findElement(By.xpath("//table[@id='MainContent_gdvDefs_DXMainTable']//td[text()='"+defName+"']")).click(); } and try{ …
-3
votes
2 answers

Can't fix a 'java.util.NoSuchElement' error

I'm trying to make a program that generate either 'win' or 'lose' for a coin flip, output the data into a file, and read that data to calculate the average, but I'm getting a 'java.util.NoSuchElementException' error. I'm not entirely sure why I'm…
maxitaxi
  • 53
  • 7
-4
votes
1 answer

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 error message. I have tried using NetBeans 12.0…
-4
votes
3 answers

findElement method showing an exception

i'm need to click a button which may appear with a 50 percent chance, decided to use try/catch with findElementBy. Nevertheless try/catch doesn't work and I'm getting an exception. Maybe there is a more efficient way to handle that…
Vadim Popov
  • 49
  • 1
  • 8
-4
votes
1 answer