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
4
votes
2 answers

What is java.util.NoSuchElementException and how do i fix it?

I was trying to program a game of battleship and i ran into this error at the point where the user was prompted to enter their guess coordinates: Exception in thread "main" java.util.NoSuchElementException at…
Ashwin Gupta
  • 2,159
  • 9
  • 30
  • 60
3
votes
1 answer

Getting Input on Different Lines with String Tokenizer

I have used Scanner(System.in) for a long time, but I am now transitioning to using BufferedReader and StringTokenizer because I heard it runs faster. I am trying to read an input (shown below) using StringTokenizer. I have looked at some posts but…
3
votes
1 answer

How to handle colon (:) in the name when using Selenium in Python

I am trying to search a number in a web page (https://muisca.dian.gov.co/WebRutMuisca/DefConsultaEstadoRUT.faces). I know the name of the input element is: "vistaConsultaEstadoRUT:formConsultaEstadoRUT:numNit", however when I try to find the element…
3
votes
2 answers

NoSuchElementException error after reading the final line of a text file

Example of text file that I am trying to read in One of the most characters in fiction is named "Tarzan of the ." Tarzan was raised by a/an and lives in the jungle in the heart of darkest . He…
Mana
  • 49
  • 6
3
votes
1 answer

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 | NumberFormatException (ATTEMPT 2) NoSuchElementException (ATTEMPT…
3
votes
1 answer

Spark streaming 2.11 - java.util.NoSuchElementException: None.get error when executing SQL function

Issue I'm using Spark to join the contents of CSV files. After I do the first join, with the streamed CSV file I am able to write the stream with no error and can see it has many rows were output, but once I try to write my second stream I get an…
3
votes
3 answers

Selecting item in nested html Frame with Selenium WebDriver

I'm attempting to use Selenium WebDriver to select a link named cslLogin on a web page. It's located in a child frame called topframe but I can't access it, even after I switch to its parent frame TopLevelFrame which I can do successfully. The html…
ntasker
  • 33
  • 4
3
votes
2 answers

NoSuchElementException in Play Framework while sending email?

Below, I have pasted my code for sending mail with attached file. I don't what I missed in my code but I am getting a NoSuchElementException in my web application. Can anyone tell what I am missing or is there a problem with the server part? Do I…
Vicky
  • 921
  • 1
  • 11
  • 33
3
votes
5 answers

no such element exception scanner

Scanner s = new Scanner(new File("src/mail_list")); while (s.hasNextLine()){ String line1 = s.nextLine(); if (line1.startsWith("Users")){ line1 = s.nextLine(); while (!(line1 = s.nextLine()).isEmpty()) { …
Pavlos Panteliadis
  • 1,495
  • 1
  • 15
  • 25
3
votes
3 answers

Why is this code getting a Java NoSuchElement exception?

I have traced through this code and can't figure out how to fix it. When running the code why wouldn't the user be prompted for input rather than Java determining that there is no input? Error trace below. import java.util.*; public class…
Efie
  • 1,430
  • 2
  • 14
  • 34
3
votes
2 answers

NoSuchElement using scanner

I have declared two strings and reading the input using Scanner(System.in). After this when i am closing the Scanner and again reading the another input using the Scanner,then it throws an error: NoSuchElementException. Please guide me on this …
Vivek
  • 49
  • 3
3
votes
3 answers

"no such element" exception when using Selenium with C#

I have a web page in my web project “CalculatorWeb” where I placed a single text box with id “txtNum1”
Asif
  • 393
  • 9
  • 17
3
votes
5 answers

Selenium: NoSuchElementException in Internet Explorer

I'm trying to port a Selenium script for an internal Webapp from Selenium IDE to a Selenium Grid setup with RemoteWebDrivers in Java. The scripts work fine with Chrome and Firefox, but not in Internet Explorer. Every time I try to find an element in…
3
votes
1 answer

NoSuchElementException on Queue

I'm having some problems with a Queue in Java. It's declared as follows: Queue touchQueue = new LinkedList(); I only add elements in one place (but on a callback, most likely called from a thread): @Override public…
3
votes
2 answers

I keep getting "Exception in thread "main" java.util.NoSuchElementException"

So I'm trying to make a simple program in Java that reads a text file (from a command line argument) and the user can check to see if a number they input is in the text file. File inputFile = new File(args[0]); Scanner scanman = new…
Edax
  • 37
  • 1
  • 2
  • 7
1
2
3
38 39