0

私はかなり新しく、Java使用してBlueJいます。エラーが発生し続けます:

incompatible types

自明のように聞こえますが、問題を解決する方法がわかりません。誰かが私を助けてくれることを願っています。前もって感謝します。

へのコードは次のclass Program2とおりです。

import java.util.*;

public class Program2 {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        Catalog store = new Catalog(3);
        int itemnum;
        Item item;

        try {
            store.insert
              (new Music(1111, "Gold", 12.00, "Abba"));
            store.insert
              (new Movie(2222, "Mamma Mia", 16.00, "Meryl Streep"));
            store.insert
              (new Book(3333, "DaVinci Code", 8.00, "Dan Brown"));
              store.insert
            (new Music(4444, "Legend", 15.00, "Bob Marley"));
            } catch (CatalogFull exc) {
                System.out.println(exc);
            }

        //  Insert code here to perform a sequence of
        //  interactive transactions with the user.
        //  The user enters an item number and the program
        //  either displays the item or prints an error message
        //  if the item is not found.  The program terminates
        //  when the user enters zero as the item number.

        while (!item.equals("0")) {
            item = store.find(itemnum);
            if (item != null) {
                System.out.print(itemnum);
            } else {
                System.out.printf("%s was not found.%n", item);
            }
            System.out.println();
            System.out.print("Player (0 to exit)? ");
            itemnum = kbd.next(); //Error on "()"
        }
    }
}
4

1 に答える 1

2

文字列は整数に代入できません

nextInt() since itemnum isを使用しint、 as をnext() 返しますString。したがって、互換性のない型です。

itemnum = kbd.nextInt();

いいえ

itemnum = kbd.next();

そして、別のタイプを参照してください

于 2013-10-01T07:36:26.730 に答える