Eclipse扫描仪行为不一致

时间:2018-12-22 21:28:34

标签: java eclipse java.util.scanner

我有两种方法要求键盘输入。在一种方法中,它可以正常工作。在另一个我得到错误:

  

线程“主”中的异常java.util.NoSuchElementException:找不到行   在java.util.Scanner.nextLine(未知来源)

以下是方法:

此功能正常

public static int logon(Connection conn,boolean flag) throws Exception{       

    Scanner kboard   = new Scanner(System.in);
    boolean exit     = false;        
    int     usr      = -1,
            spaces   = 0,
            commaChk = 0;                
    String input;        
    String[] tokens  = new String[3];

    //ask for user input
    do{
        printHeader(0);

        System.out.print( "Please enter first name, last name and password to logon or create a new account \n" +
                          "use a space to seperate entries, no commas                                     : ");

        input = kboard.nextLine();

        if(input.length() == 0) exit = true;

这将返回错误

public static int generalPrompt()throws Exception{
    Scanner kboard = new Scanner(System.in);        
    String input; 
    int selection = 0;
    String[] myInts ={"1","2","3","4","5","6"};
    boolean goodInput = false;

    do{               
        printHeader(0);
        printHeader(1);

        System.out.print("\n\n Select number from above ([return] to exit) : ");

        input = kboard.nextLine();

        if (input.length() == 0){

0 个答案:

没有答案