我对Java相当陌生,而且我正在使用BlueJ。在尝试编译时,我一直得到这个“Int不能被解除引用”的错误,我不确定问题是什么。该错误具体发生在我的if语句底部,它表示“equals”是一个错误,“int不能被解除引用”。希望得到一些帮助,因为我不知道该怎么做。先谢谢你!Java中的“int无法解除引用”
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.equals(list[pos].getItemNumber())){ //Getting error on "equals"
return list[pos];
}
else {
throw new ItemNotFound();
}
}
}
}
你试图使用'int'其中一个'Integer','Number'或'Object'预计...'INT '没有任何方法 – MadProgrammer