【发布时间】:2021-01-22 04:38:02
【问题描述】:
我在 Netbeans Gradle Java 应用程序下运行以下代码时遇到了一个问题。
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();
}
}
}
发生错误
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)
但是,我在没有 Gradle 的简单 Java 应用程序中编写了相同的代码,没有出现问题。 我只是想知道我做错了什么?
【问题讨论】:
标签: java gradle netbeans nosuchelementexception