我正在編寫一個有兩個類的程序。第一個類有一個數組,它將能夠將其他類添加到它的數組中,長度爲10.但是,我得到錯誤說「找不到符號」。 所以我的問題是我如何添加一個單獨的類到另一個類的數組?將一個類對象添加到數組中
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Arrays;
public class HomeInventoryManager
private int[] listOfInventoryItems;
/**
* Initialise the home inventory manager.
*/
public HomeInventoryManager()
{
listOfInventoryItems = new int[10];
InventoryItem = 0; **i get the error here saying it cannot find the symbol variable InventoryItem**
}
public void addInventoryItem()
{
listOfInventoryItems[InventoryItem] = anInt;
inventoryItem++;
}
** inventoryItem **是一個int還是一個單獨的類? –
它是一個單獨的類 –
你可以把庫存物品的代碼。否則不能告訴確切的解決方案。總之,您應該調用該類中的方法來增加inventoyItem計數。 –