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

Selenium webdriver: verify multiple text in a page

I have a page which will give any one of the three messages (error, warning and success) on form submit. The problem is only one message will be visible at a time and for the rest i am getting 'NoSuchElementException'. My current code is: String…
TheIlliterate
  • 119
  • 2
  • 9
-1
votes
1 answer

java.util.NoSuchElementException found while using Scanner

I am a new newbie and trying to learn and practice java code simultaneously. Its really basic but still i am stuck. While coming across Scanner class, i am facing below error. I am already through a lot many solutions provided earlier over here but…
-1
votes
1 answer

Java filepath errors

I am writing a program that determines the type of triangle based on the length of its sides which is provided using a separate .txt file. My code: import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class…
rburrus
  • 19
  • 2
-1
votes
1 answer

Selenium WebDriver(3.3.1.JAR) with WIN10 64bit, IE11

-I m using Selenium webdriver(3.3.1.Jar) with TestNG in Win10 x64bit, IE11 and my code is working for other broswers(Chrome, Firefox) except IE11. -I made protected security mode to same unchecked -set JAVA_HOME & Path in Env variables -Changed…
-1
votes
2 answers

NoSuchElementException break in while loop after first iteration?

My code is running fine at the beginning, but in the while loop, it won't prompt the user for the next input, and is just responding with no such element exception. I have tried fixing it for at least an hour, and have had no luck. Any tips on what…
-1
votes
2 answers

How do I get int values out of a string using two scanner objects?

I'm really new to coding and right now I need to take an input from the user in one line seperated by spaces for example "0 1 2" and then take the ints in that string and place them in separate int variables. This is what I have so far: Scanner scan…
-1
votes
1 answer

Selenium webdriver script is not able to click any element after successfully login

I tried all possible element locators but after successfully login the code is unalbe to click the element I want it to click. I get following error: ... class charSequence { String str1="abcdef@gmail.com"; String str2= "abcdfghhh"; …
user6819480
-1
votes
1 answer

how to stop testsuite when a testcase threw out NoSuchElementException

I put 4 testcases into one testsuite and in each testcase I have code to catch the NoSuchElementException. I want: if any one testcase threw out NoSuchElementException, the testsuite execution should stop. For Example, if first testcase throws…
-1
votes
1 answer

Scala java.lang.NoSuchElementException Error

I have a Scala for loop that goes like this: val a = sc.textFile("path to file containing 8 elements") for(i <- 0 to a.count.toInt) { println((a.take(i).last)) } But it throws java.lang.NoSuchElementException error. I am not able to understand…
-1
votes
1 answer

JAVA - Method works for 1st call, but not for 2nd

I have a method called isValidFile which takes in a user input string and determines if that is a valid file. The method output is of the File type. I am able to take in 2 file names in the command line and process them properly. I am also able…
-1
votes
3 answers

NoSuchElementException in - Java

I am trying to read data from a text file and then store it to an array. I assume that there is one word per line. I am getting a NoSuchElementException here: while (s.hasNextLine()) { text = text + s.next() + " "; } This…
Lora Gonzales
  • 53
  • 1
  • 1
  • 6
-1
votes
1 answer

"Java.util.NosuchelementException" I am getting and also n value is fault

nani.txt contains values such as 12 6 6 3 1 5 10 8 9 2 import java.io.*; import java.io.File; import java.util.*; import java.util.Scanner; import java.util.Arrays; class Point { int x, y; } /** Class Jarvis…
-1
votes
1 answer

Java I/O program, java.util.NoSuchElementException

I'm working on a program that reads input from a text file and outputs it into multiple .csv files. I'm running into issues with my driver class and inputFile class. When I run the program I get this error This is my code for the driver: import…
Mr_Traum
  • 11
  • 3
-1
votes
1 answer

Exception in thread "main" java.util.NoSuchElementException Runtime error getting proper output

Given a number N, find the sum of all products x*y such that N/x = y (Integer Division). Since, the sum can be very large, please output this modulo 1000000007. Input The first line of input file contains an integer T, the number of test cases to…
-1
votes
1 answer

How do I overcome NoSuchElementFoundException?

I'm having a NoSuchElementFoundException but I'm unable to find the line where the pb is. Whenever my program receives SMS it throws this exception. Bundle bundle = intent.getExtras(); Object[] messages = (Object[]) bundle.get("pdus"); SmsMessage[]…