我在运行时收到错误

好吧,我遇到了一个错误,我不太确定为什么,任何帮助,将不胜感激。 当我尝试运行它时,遇到以下情况。

java.util.Scanner.nextInt java.util.Scanner.throwFor(Scanner.java:907)at java.util.Scanner.next(Scanner.java:1530)java.util.NoSuchElementException Scanner.java:2160)位于JonesInc.main处的java.util.Scanner.nextInt(Scanner.java:2119)(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;   
           }
       }
    }
}

您正在运行程序(似乎至少在表面上正常工作)以某种不允许交互式输入的方式运行。

Scanner试图阅读这里:

int choice=kbReader.nextInt();

但是System.in已经关闭。

您应该以支持通过System.in输入数据的方式运行程序,例如在任何主要的IDE中。

链接地址: http://www.djcxy.com/p/96077.html

上一篇: I'm receiving an error on run

下一篇: Java scanner skips input nextLine() but not next()