Java中的不兼容类型。希望有所帮助

BBladem83

我是新手,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 "()"
        }
    }
}
苏雷什·阿塔(Suresh Atta)

字符串不可分配给整数

使用nextInt()sinceitemnumint,其中as作为next()返回值String,因此使用不兼容的类型。

itemnum = kbd.nextInt();

不是

itemnum = kbd.next();

并看到不同的类型

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Java中不兼容的类型

我希望在 jekyll 中当前年份和给定年份之间有所不同

Spring Boot中的Java接口是否有所不同?-这是Spring Wizardry,还是我不了解界面?

如何使子画面螺旋向中心旋转(在Java中,但如果您知道一个公式,也会有所帮助)

错误:不兼容的类型:推断变量R具有不兼容的界限(Lambda Java 8)

Java:for循环,不兼容的类型

不兼容的对象类型-Java

Java Gson不兼容类型

Java不兼容类型错误

为什么“收益自我”会有所帮助?

Java中的File.createTempFile获取不兼容的类型错误

List <List <?>>和List <List>是Java中不兼容的类型

类型不兼容的Java中的此错误是什么?

如何在Java中解决这种不兼容的类型?

java:不兼容类型:推断变量T具有不兼容边界等式约束:下界:java.util.List <>

不兼容的类型:推断变量T具有不兼容的边界相等约束:捕获的#1?扩展java.lang.Object

Scala值具有不兼容的类型?

Java泛型不兼容的类型(类型的变量没有实例(S)(S)存在)

Java泛型不兼容的类型(类型的变量没有实例(S)(S)笔存在)

intern()在Java 6和Java 7中的行为有所不同

继承类的Java不兼容类型

解决,不兼容的类型错误,Java 8

Java-错误:返回类型不兼容

Java 8函数-不兼容的类型

Java JUNG-不兼容的类型

Java和Hadoop:与TextInputFormat不兼容的类型

Java错误:“类型不兼容”消息

Java泛型:不兼容的类型

不兼容类型的泛型Java