in this bit:"System.out.println("The entry for: " + InventoryItem.getName()+ " has been removed");"
how do you make the name of the book shown after"The entry for: "??? code " InventoryItem.getName()" doesnt work actually~~~error message coming out:" non-static method getName() cannot be referenced from a static context"
AND basically in my InventoryItem, it looks like:
so where is the problem???
[ March 22, 2006: Message edited by: Jose Cisse ]
[ March 22, 2006: Message edited by: Jose Cisse ] [ March 22, 2006: Message edited by: Jose Cisse ]
Your inventory class does not seem to have a method called "get," so "inventory.get()" does not work.
Your inventory class does not seem to have a method called "remove," so "inventory.remove()" does not work.
Is there a method in your inventory class that you want to call?
Hint: I think you took a wrong turn several posts above when an assumption was made that "inventory" represented an ArrayList.
Joined: Nov 02, 2005
Hmm, sorry I didn't read it properly - I was assuming inventory was the ArrayList.
You won't be able to call get() on your inventory item because you haven't defined a get() method. You can either define a get() method and your code snippet should work, or you could change your inventory class so that the removeItem() method returns the item you have removed. Wither way will obtain a reference to the item you are about to remove so that you can call getName() on it.
Another tip - you should capitalise class names, so call your class Inventory rather than inventory.
Joined: Mar 20, 2006
i think i defined get() method in my InventoryItem class, plz have a look:
Originally posted by Jose Cisse: i think i defined get() method in my InventoryItem class...
No. InventoryItem has a few "getter" methods: getName, getDescription, and getPrice. But it does not have a method simply called "get."
Also, Inventory and InventoryItem are two different classes, neither of which extend the other. So even if InventoryItem did have a "get" method, that would not allow you to call "get" on an instance of Inventory. [ March 23, 2006: Message edited by: marc weber ]