簡體   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