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
89
votes
6 answers

java.util.NoSuchElementException - Scanner reading user input

I'm new to using Java, but I have some previous experience with C#. The issue I'm having comes with reading user input from console. I'm running into the "java.util.NoSuchElementException" error with this portion of code: payment = sc.next(); //…
fortune
  • 1,527
  • 2
  • 15
  • 22
24
votes
10 answers

What is the best way to avoid NoSuchElementException in Selenium?

I have written few test cases in Selenium WebDriver using Java and execute them on grid (hub and multiple nodes). I have noticed that a few test cases fail due to NoSuchElementException. What is the best and robust way to avoid…
19
votes
1 answer

Selenium "selenium.common.exceptions.NoSuchElementException" when using Chrome

I'm trying to play QWOP using Selenium on Chrome but I keep getting the following error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element {"method":"id","selector":"window1" (Session info:…
16
votes
1 answer

java.util.NoSuchElementException using iterator in java

I'm trying to iterate through a list using the iterator over my list of Logs. The goal is to search for a logs which contains the same phonenumber, type and date as the new log However, I get a java.util.NoSuchElementException in my conditional…
Frederikkastrup
  • 243
  • 1
  • 3
  • 11
15
votes
1 answer

Observable.empty() causes java.util.NoSuchElementException: Sequence contains no elements

I'm using Retrofit 2.0.0-beta2 with RxJava 1.0.14. I handle errors this way because I need to execute some code in doFinally: .onErrorResumeNext(Observable.empty()); But when I get a http response with an error (401 for example) my app crashes with…
Anton Shkurenko
  • 4,301
  • 5
  • 29
  • 64
10
votes
1 answer

Spark throws java.util.NoSuchElementException: key not found: 67

Running the Spark bisecting kmmeans algorithm in Zeppelin. //I transform my data using the TF-IDF algorithm val idf = new IDF(minFreq).fit(data) val hashIDF_features = idf.transform(dbTF) //and parse the transformed data to the clustering…
Mnemosyne
  • 1,162
  • 4
  • 13
  • 45
10
votes
3 answers

LinkedList : Collections.max() throwing NoSuchElementException

I am not iterating the LinkedList by any means like scanner or other methods, I am using Collections.max() to get maximum number from the LinkedList. I have read on Stack Overflow that this exception is thrown due to iterator or scanner or…
PankajKushwaha
  • 878
  • 2
  • 11
  • 25
7
votes
8 answers

org.openqa.selenium.NoSuchElementException: no such element

Running Selenium WebDriver 2.37.1 I'm receiving an intermittent problem when running a test and receive the following error: org.openqa.selenium.NoSuchElementException: no such element Sometimes the test will pass, most of the time it will fail.…
Django_Tester
  • 139
  • 1
  • 3
  • 16
6
votes
0 answers

Spark Scala - java.util.NoSuchElementException & Data Cleaning

I have had a similar problem before, but I am looking for a generalizable answer. I am using spark-corenlp to get Sentiment scores on e-mails. Sometimes, sentiment() crashes on some input (maybe it's too long, maybe it had an unexpected character).…
6
votes
2 answers

.NET Selenium NoSuchElementException; WebDriverWait.Until() doesn't work

We have a .NET 4.5, MVC, C# project. We're using Selenium for UI tests, and the tests keep intermittently failing on lines that we have wait.Until(). One such example is: NoSuchElementException was unhandled by user code An exception of type…
levininja
  • 3,118
  • 5
  • 26
  • 41
5
votes
5 answers

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; public class Nope { public static void…
Paris
  • 73
  • 1
  • 9
5
votes
3 answers

C# Selenium - Is there any way to check if the Element Exists or not without throwing NoSuchElementException

Is there any way to check if the element exists on the page without throwing an exception using selenium C#.
user4472042
  • 61
  • 1
  • 2
5
votes
3 answers

Scanner - java.util.NoSuchElementException

Does anyone see a problem with this? First input works fine, but after the first loop, it doesn't ask to enter a value again. How do I fix this? int value; while(true) { Scanner scan = new Scanner(System.in); …
Alan
  • 153
  • 1
  • 4
  • 11
4
votes
4 answers

Handle the NoSuchElementException in Fluent Wait

I know that in terms of waiting for web element that isn't in the DOM yet, the most efficient is a fluent wait. So my question is: Is there a way to handle and catch the NoSuchElementException or any exception that fluent wait might throw because…
4
votes
3 answers

How to decrease the wait time for NoSuchElementException in Selenium?

In some cases, i know element will not be displayed. but its waiting ~30 Secs. How to decrease wait time for NoSuchElementException in selenium? Sample code: String name; try { name =…
1
2 3
38 39