I am trying to simply get input from the user, in a method that returns Object. For some reason, this error is thrown:
Exception in thread "main" java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61) Caused by: java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651) at candle.Main.getValue(Main.java:381) at candle.Main.runFile(Main.java:979) at candle.Main.main(Main.java:1013) ... 5 more
Here is a code snippet:
System.out.print("> ");
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
scanner.close();
Can anyone explain how to get this work, or point out something I have done wrong? Thanks.