nosuchelementexception

How to close a scanner without closing the underlying System.in?

邮差的信 提交于 2019-12-13 01:30:48
问题 If I close one scanner object and make a new one and try to read some more input, I'm getting the NoSuchElementException exception. My code works fine but it gives me a warning if I don't close the scanner. However, if I close it to get rid of the warning, I also close System.in ... How do I avoid this? Also, are there any consequences of not closing the scanner? EDIT: Here's my code: This is the NameAddressExists() method: public void NameAddressExists() { System.out.println("Enter name");

How to customize Selenium test error/fail message

爷,独闯天下 提交于 2019-12-12 00:41:02
问题 I'm using VS2012 and i want to customize my selenium tests. For example, when test fails, i want to show the text The page loaded too long - unable to login + original message instead of showing only this: OpenQA.Selenium.NoSuchElementException: Unable to find element with id == loginElementID . Is it possible? How and when to use Assertions when UI testing? That would make my tests more understandable and informative. var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 0, 8)); wait

Hadoop MapReduce NoSuchElementException

安稳与你 提交于 2019-12-11 19:54:07
问题 I wanted to run a MapReduce-Job on my FreeBSD-Cluster with two nodes but I get the following Exception 14/08/27 14:23:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 14/08/27 14:23:04 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id 14/08/27 14:23:04 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId= 14/08/27 14:23:04 WARN

Scanner not asking for input , throws No Such Element Exception - multiple scanners

坚强是说给别人听的谎言 提交于 2019-12-11 10:37:10
问题 In the below code I have used two scanners, One in performAction() method and one in getTicketNumber() method. I have used try with resources and once when I go into getTicketNumber() method, it works fine and once when the control returns back and comes to performAction() I am getting No Such Element Exception when it executes the scanner.nextInt() line. I wanted to continue this process until I press exit. I guess it is due to the use of multiple scanners since if I don't go into

java.util.NoSuchElementException Error when closing the Scanner

不想你离开。 提交于 2019-12-11 10:15:09
问题 public class a2 { public static int read() { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); sc.close(); return num; } public static void out (int a, int b) { System.out.println("Sum: " + (a+b)); System.out.println("Difference: " + (a-b)); System.out.println("Product: " + (a*b)); System.out.println("Quotient: " + ((double)a/(double)b)); System.out.println("Remainder: " + (a%b)); } public static void main(String[] args) { System.out.println("Please enter two integers!:"); int a =

Java: java.util.NoSuchElementException: No line found

白昼怎懂夜的黑 提交于 2019-12-11 05:37:13
问题 I have a problem and don't know what to do. Here's the exception: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at Auto.<init>(Auto.java:32) at Auto.main(Auto.java:22) And that's my Code: import java.util.Scanner; public class Auto { private String Marke1; String Modell1; String Farbe1; double Höhe; double Breite; double Länge; int Tueren = 4; public static void main(String[] args) { System.out.println("Hello Auto!");

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

ⅰ亾dé卋堺 提交于 2019-12-11 03:49:25
问题 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 java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at game.User.takeTurn(User.java:121) at game.Game.main(Game.java:61) Here is the method User.takeTurn() where the

How to decrease the wait time for NoSuchElementException in Selenium?

北城以北 提交于 2019-12-10 18:16:29
问题 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 = driver.findElement(By.xpath("XPath")).getText(); } catch (NoSuchElementException e) { name = "Name not displayed"; } 回答1: I think you're looking for setting the implitic wait time for your driver: driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); For simple cases thats ok to use, for more advanced

Exception in thread “main” java.util.NoSuchElementException: No line found 3 [duplicate]

妖精的绣舞 提交于 2019-12-10 12:24:22
问题 This question already has an answer here : How to use java.util.Scanner to correctly read user input from System.in and act on it? (1 answer) Closed last year . In this code, throws me this exception: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1540) at com.cristianvalero.filetransfers.main.client.Client.askToDo(Client.java:98) at com.cristianvalero.filetransfers.main.client.Client.run(Client.java:64) at com

Scanner throwing NoSuchElementException

≡放荡痞女 提交于 2019-12-08 03:38:03
问题 I am trying to create a simple small program that will ask for a positive int and won't crash or close until it has received a positive int from the user. However my program keeps crashing, and reporting the error NoSuchElementException, when it calls the method with Scanner in it more than once. I will be using the fundamentals of this program to help some other things I am working on. Here is my current code; import java.util.InputMismatchException; import java.util.Scanner; public class