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
3 answers

Got exception in thread "main" java.util.NoSuchElementException

Just started doing java programming. I searched stackoverflow and saw various solutions for this error but none of them solved the issue in my program. The program stops at "ENDDATA". I'm sure it is a simple fix that I can't seem to figure…
-1
votes
2 answers

Copy List with "addAll" method NoSuchElementException
I think I have a problem in my code, but I can't find why. When I'm using chemin.next() its working fine. But when I do new_chemin.addAll(chemin.next()); I have a NoSuchElementException public Zone cherche_chemin(List> chemins,…
pred
  • 185
  • 1
  • 14
-1
votes
2 answers

Inheritance No Such Element?

I looked for a similar problem but couldn't really apply any of the solutions to mine. I'm testing the code for a program that's supposed to read information about a car purchase from a file, but in my TestDrive class it keeps giving this error…
noremacb
  • 19
  • 2
  • 6
-1
votes
1 answer

NoSuchElementException error

I am trying to see if the next token in a string is equivalent to map key, and adding a message to an array list. ArrayList trace = new ArrayList(); if(!element.startsWith("PRINT")) { while(st.hasMoreTokens()) { …
-1
votes
1 answer

NoSuchElementException for my poker game Java

I could really use your help! I fixed most of the errors but im stuck on this one at the moment. Sorry for the long code and please let me know if you see any additional errors or mistakes i might have missed. I really appreciate your help <3 I…
-1
votes
3 answers

Getting a NoSuchElementException 33

I don't know why I am getting this error. What should I do to fix it? Any help really appreciated. I excluded code that does not affect the error. Line 33 is String string1 = token.nextToken(); import java.net.*; import java.io.*; import…
-1
votes
2 answers

java.util.NoSuchElementException when working with .equals, arraylist and reading file with scanner

I'm attempting to populate an arraylist of strings with a text file that contains spaces, such that each string in the arraylist would contain a space between the first and second numbers in it, and no leading or trailing spaces. I am unfortunately…
-1
votes
1 answer

Getting NoSuchElementException when running this method

My method runs, but then gets an exception after executing once. I don't understand why. Line 24, the line noted in the exception, is at "choice=in.nextInt();" Here is my exception: 1 Find an item. 2 Display all items. 3 Update item. 4…
Corey
  • 264
  • 2
  • 10
-1
votes
1 answer

My java.util.Scanner won't work

My code is getting this error: Skriv din alder herunder og tryk enter: Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:907) at java.util.Scanner.next(Scanner.java:1530) at…
Kevin Steen Hansen
  • 555
  • 2
  • 6
  • 17
-2
votes
2 answers

NoSuchElementException when HashMap Iterator hits empty line

Hi i'm doing some training on ArrayLists and HashMap. I'm parsing a file with BufferedReader, add each line to the ArrayList readList and now I like to create a HashMap map where the Key is the readList entry and the Value is the…
user18906827
-2
votes
1 answer

Selenium can't find element by name: NoSuchElementException

I'm trying to learn Python better by doing automation. My project right now is creating a bot that will log in to Instagram. My code is as follows: def login(self): self.driver.get('https://www.instagram.com/accounts/login/') …
-2
votes
1 answer

If keep receiving runtimeException

The following code works fine with the eclipse but then in online editor I keep receiving runtimeException(NoSuchElementFoundException) please help me where am I going wrong? {I have used sieve of eratosthenes alogirthm to find prime number in…
Kirthi
  • 13
  • 2
-2
votes
1 answer

Getting a weird NoSuchElementException

We are trying to compile our program, but we keep getting a NoSuchElementException. Anyone that has a clue on why this keeps occurring? Thanks in advance. In the following I will attach both the code where we implement the exception and also the…
-2
votes
1 answer

How to get to the element through JS in iframe? Selenium, Java

So what we have - there's an iFrame on page which shows a preview of previously generated data. I need to get element with text and then get CSS value from it. Take a look at the DOM here: example of the page xpath to this element looks right to…
-2
votes
1 answer

Confused about NoSuchElementException in Java

I'm working on a Choose Your Adventure game in Java, and I'm really confused why I'm getting a NoSuchElementException when the variable adolescenceIntro is used (see main function). The birth variable and all of the variables it calls work…
kjames
  • 39
  • 1
  • 7