[英]I'm receiving an error on run
Okay so I've encountered an error and I'm not so sure why, any help would be appreciated. 好的,所以我遇到了一个错误,但是我不确定为什么,任何帮助将不胜感激。 When I try run it, I'm met with the following. 当我尝试运行它时,遇到了以下问题。
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:907) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextInt(Scanner.java:2160) at java.util.Scanner.nextInt(Scanner.java:2119) at JonesInc.main(JonesInc.java:16) Java.util.Scanner.next(Scanner.java:1530)处java.util.Scanner.next(Scanner.java:1530)处java.util.Scanner.throwFor(Scanner.java:907)处的线程“ main”中的java.util.NoSuchElementException异常。位于JonesInc.main的java.util.Scanner.nextInt(Scanner.java:2119)的Scanner.java:2160)(JonesInc.java:16)
public class JonesInc
{
public static void main(String[] args)
{
Scanner kbReader=new Scanner(System.in);
System.out.println("1. Administration");
System.out.println("2. Check Stock Availability");
System.out.println("3. Purchase Textbooks");
System.out.println("4. Return Textbooks");
System.out.println("5. Quit");
System.out.println("please select your choice");
int choice=kbReader.nextInt();
int stock=100;
if(choice==1)
{
Scanner password=new Scanner(System.in);
System.out.println("Please Enter Password");
String name=password.nextLine();
if(name.equals("Java"))
System.out.println("A. Increase Stock Availabilty");
System.out.println("B. Reduce Stock Availability");
System.out.println("C. Quit");
System.out.println("Select your choice");
Scanner kbReader1=new Scanner(System.in);
String choice1=kbReader1.nextLine();
char ch=choice1.charAt(0);
System.out.println("");
switch (ch)
{
case'A':
case'a':
System.out.println("How much do you wish to increase stock by");
break;
case'B':
case'b':
System.out.println("How much do you wish to decrease stock by");
break;
case'C':
case'c':
System.out.println("Dave is cool");
break;
}
}
}
}
You're running the program (which seems to work correctly, at least superficially) in some way which doesn't allow interactive input. 您正在以某种不允许交互输入的方式运行该程序(至少在表面上似乎正常运行)。
The Scanner
tries to read here: Scanner
尝试在此处阅读:
int choice=kbReader.nextInt();
but System.in
is already closed. 但是System.in
已经关闭。
You should run the program in a way that supports inputting data via System.in
, eg in any major IDE. 您应该以支持通过System.in
输入数据的方式运行程序,例如在任何主要IDE中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.