Method cannot be applied to given types. Hope for assistance

I'm fairly new to `Java` and I'm using `BlueJ`. I keep getting the error: method find in class Catalog cannot be applied to given types; required: int found: Item reason: actual argument Item cannot be converted to int by method invocation conversion I'm very confused and in turn not sure how to fix the problem. Hopefully someone can help me. Thank you in advance. Here is my Program2 class: 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")) { itemnum = store.find(item); //Getting error on ".find" if (itemnum != 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)? "); item = kbd.next(); } } } For reference, here is the `class Catalog` as well: public class Catalog { private Item[] list; private int size; // Construct an empty catalog with the specified capacity. public Catalog(int max) { list = new Item[max]; size = 0; } // Insert a new item into the catalog. // Throw a CatalogFull exception if the catalog is full. public void insert(Item obj) throws CatalogFull { if (list.length == size) { throw new CatalogFull(); } list[size] = obj; ++size; } // Search the catalog for the item whose item number // is the parameter id. Return the matching object // if the search succeeds. Throw an ItemNotFound // exception if the search fails. public Item find(int id) throws ItemNotFound { for (int pos = 0; pos < size; ++pos){ if (id == list[pos].getItemNumber()){ return list[pos]; } } throw new ItemNotFound(id); } }
You try to put Item as int, so where is Item definition? I'm sure it should be something like store.find(item.getId()) or store.find(item.id)

以上就是Method cannot be applied to given types. Hope for assistance的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏