I've created a java project in IDE Netbeans 12 ( java with Gradle ). And when I was trying to run a simple "get input" code as below:
package hi;
import java.util.Scanner;
public class Main {
public static void main( String args[] ){
Scanner scan = new Scanner( System.in );
int number = scan.nextInt();
System.out.print( number );
}
}
I got an error:
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at hi.Main.main(Main.java:7)
I used try catch
to determine the error occurred on the line int number = scan.nextInt();
. It just happened when building Java project with Gradle, others are fine.
I tried to find out on Google search but it looks like I have not found any solution or the reason of the error.
Anyone here helppppp