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

Weird NoSuchMethodError with gibberish explanation

I have the following code in my SDK: public MatchDomainTrustManager(String domain) throws GeneralSecurityException, AssertionError { if (domain == null) throw new IllegalArgumentException("domain can not be null"); this.domain =…
Keselme
  • 3,779
  • 7
  • 36
  • 68
2
votes
1 answer

No such element exception but the element is clearly there

I am trying to write code that automates an android app to do everything you would do with your fingers. The goal now is to get it to select a picture. I typed this line so it selects the element through the resource-id from…
2
votes
2 answers

NoSuchElementException on reopening the scanner within a method

Here's a reduced version of the code that's throwing the exception. static String s1; static String s2; static void getString(String s) { Scanner sc = new Scanner(System.in); s = sc.nextLine(); sc.close(); } public static void…
2
votes
3 answers

How to read from file and store the information in a Linked List (Java)?

I'm trying to read a file that contains attributes that create a CellPhone (such as serial number, brand, year, and price). Then, I want to store the information in variables so that I can create CellPhone objects using its constructor. Afterwards I…
Joey
  • 23
  • 3
2
votes
2 answers

Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862)

I really don't see what the problem could be. This is the error I'm getting: $javac Palindrome.java $java -Xmx128M -Xms16M Palindrome Enter your word Exception in thread "main" java.util.NoSuchElementException at…
oakanb2
  • 41
  • 1
  • 2
  • 6
2
votes
1 answer

Scanner.nextInt() NoSuchElementException

I got this code (sorry for the german inside): public void eingabewerte(){ int steuerInt; steuerInt=-1; Scanner myScanner = new Scanner(System.in); System.out.println("Bitte geben Sie die maximal Augenzahl des Wuerfels an…
2
votes
1 answer

How to make CTRL+Z NOT mess up a java console program

One of my final project requirements is that, if it is console based which mine is, entering ctrl + z WON'T mess up the program. The nextLine() statement from my scanner is within a while loop, and when I try to catch the NoSuchElementException from…
theolaa
  • 33
  • 8
2
votes
2 answers

Selenium in Java: Not able to locate element on Amazon

I am trying to get the text for Rating of any product on Amazon but I am unable to write the correct code. I don't understand what I am doing wrong here. Here its not even able to locate the element. Also I don't think xpath is wrong because I…
2
votes
3 answers

NoSuchElementException : Unable to select image from gallery

I am using nexus 5 to test. How can i choose image from gallery using appium in android. When i used following code : driver.findElement(By.xpath("//android.widget.ImageView[@content-desc='Photo taken on 13 May 2016 12.50']")).click(); I got…
2
votes
1 answer

NoSuchElementException While using Collections.min(List, Comparator) when List is not empty

I am getting NoSuchElementException while using Collections.min, I have read other related questions too on the site, and learned that one gets this exception if the list or collection used is empty. But I have checked debugging the code, the list…
Preeti Singh
  • 37
  • 3
  • 12
2
votes
0 answers

NoSuchElementException while declaring second object

I have this simple code where I'm trying to make two objects of a class and then call a function in that class but I'm getting NoSuchElementException on the 42 line i.e. where i declare the second object. da import java.io.*; import…
2
votes
1 answer

FindBugs can't throw NoSuchElementException

I have following code snippet: @Override public Message next() { if (!this.hasNext()) { throw new NoSuchElementException(); } // return statement } However, findbugs says that there is BAD_PRACTICE: It: Iterator next() method…
2
votes
1 answer

Selenium: NoSuchElementException

I'm trying to scrape this page: http://www.ebay.com/itm/311419628966 using the following XPath: • .//*[@id='ds_div'] • .//*[@id='pdets'] • .//*[@id='centercolumn']/ But they all throw NoSuchElementException. This is odd because when I inspect the…
Jim Kim
  • 33
  • 1
  • 4
2
votes
4 answers

java.util.NoSuchElementException from Scanner

I'm having trouble with my scanner when it's reading a file. It's suppose to make a new token when there's a comma followed by a space or when a new line is created, but after the 4 tokens, it throws the NoSuchElementException. private…
Alex S.
  • 53
  • 5
2
votes
3 answers

Selenium - unable to find element- during second time

I am trying to find element like this - Select servTypeDA = new Select (driver.findElement(By.xpath("//select[@id='ServicesType']"))); servTypeDA.selectByVisibleText(servTypeData); This works fine perfectly for the first time, when I load this…