Java i/o 程序错误 throwFor(Unknown Source)

我正在制作一个程序,用于查看文本文件并将其打印到 eclipse 中的控制台。文本文件中的一行看起来像这样......

A.马修斯 4 7 3 10 14 50

运行程序时,我收到这样的错误..

http://img3.mukewang.com/61946cc6000124de06410141.jpg

这是程序


import java.io.*;    // for File

import java.util.*;  // for Scanner


public class MapleLeafLab {

public static void main(String[] args) throws FileNotFoundException {

    Scanner input = new Scanner(new File("mapleleafscoring.txt"));

    while (input.hasNextLine()) {

        String line = input.nextLine();

        Scanner lineScan = new Scanner(line);

        String name = lineScan.next(); // e.g. "Eric"

        String rest = lineScan.next();

        int GP = lineScan.nextInt();          // e.g. 456

        int G = lineScan.nextInt();

        int A = lineScan.nextInt();

        int P = lineScan.nextInt();

        int S = lineScan.nextInt();

        Double SS = lineScan.nextDouble();




        System.out.println(name+rest+" "+GP+" "+G+" "+A+" "+P+" "+S+" "+SS);


        //System.out.println(name + " (ID#" + id + ") worked " +

        // sum + " hours (" + average + " hours/day)");


    }

}

}


MM们
浏览 216回答 1
1回答

慕桂英4014372

这是 Scanner 的 Javadoc:https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.htmlpublic double nextDouble()将输入的下一个标记扫描为双精度...如果下一个标记与上面定义的 Float 正则表达式匹配,则该标记将转换为双精度值...Returns:    the double scanned from the input Throws:    InputMismatchException - if the next token does not match the Float regular expression, or is out of range    NoSuchElementException - if the input is exhausted    IllegalStateException - if this scanner is closed你得到NoSuchElementException是因为你试图从 7 个标记的行中读取 8 个标记。A.Matthews => name4 => rest7 => GP 3 => G 10 => A 14 => P 50 => SSS =>  NoSuchElementException
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java