繁体   English   中英

这段代码给我一个不兼容的类型错误。 它说它需要一个扫描器,但是找到了字符串。 我不明白该如何解决

[英]This code gives me an incompatible types error. It says it requires a Scanner but found String. I don't understnd how I can fix it

public static void getBooks(){

    int bookNum = 0;
    bookFile = new File(args[0]);
    Scanner input = new Scanner(bookFile);

    while (input.hasNextLine()) {
        bookNum += 1;
        input = input.nextLine();
    }
    ...
}

我需要它来增加书的数量,只要在下一行时有书要添加含义即可。

问题在这里:

    input = input.nextLine();

两个input s可能是两个单独的变量。 将此更改为:

    String line = input.nextLine();
    // use `line' here

input = input.nextLine(); 没有意义。 你想让我做什么? 只需运行input.nextLine()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM