I have come across an issue when running the following code under Netbeans Gradle Java Application.
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class Main {
private static int imgBundle;
private static int flacBundle;
private static int vidBundle;
public static void main(String[] args) {
takeInput();
}
private static void takeInput() {
Scanner input = new Scanner(System.in);
System.out.print("Please enter the number of Image format for the order: ");
imgBundle = input.nextInt(); // where the error occurred
System.out.print("Please enter the number of Audio format for the order: ");
flacBundle = input.nextInt(); // where the error occurred
System.out.print("Please enter the number of Video format for the order: ");
vidBundle = input.nextInt(); // where the error occurred
System.out.println("Your Order Input:");
System.out.println(imgBundle + " IMG");
System.out.println(flacBundle + " FLAC");
System.out.println(vidBundle + " VID");
System.out.println("");
System.out.println("Calculating...Please wait...");
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
}
}
An Error occurred
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 BundlesCalculator.Main.takeInput(Main.java:65)
at BundlesCalculator.Main.main(Main.java:43)
However, I wrote the same code in a simple Java Application without Gradle, there is no issue occurred.
I just wonder what did I do incorrectly?
question from:
https://stackoverflow.com/questions/65839373/same-java-code-failed-to-run-under-java-gradle-application 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…