Tôi là khá mới với Java và tôi đang sử dụng BlueJ. Tôi tiếp tục nhận được lỗi "Int không thể được dereferenced" khi cố gắng biên dịch và tôi không chắc chắn vấn đề là gì. Lỗi này xảy ra cụ thể trong câu lệnh if của tôi ở dưới cùng, trong đó có thông báo "bằng" là lỗi và "int không thể bị hủy tham chiếu". Hy vọng sẽ nhận được một số trợ giúp vì tôi không biết phải làm gì. Cảm ơn bạn trước!"int không thể được dereferenced" trong Java
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();
}
}
}
}
Bạn đang cố gắng sử dụng một 'int' nơi một' Integer', 'Number' hoặc' Object' dự kiến ... 'int 'không có bất kỳ phương thức nào – MadProgrammer