Sono abbastanza nuovo in Java e sto usando BlueJ. Continuo a ricevere questo errore "Int non può essere dereferenziato" durante il tentativo di compilazione e non sono sicuro di quale sia il problema. L'errore si verifica in modo specifico nella mia istruzione if in basso, dove si dice "equals" è un errore e "int non può essere dereferenziato". Spero di ricevere assistenza in quanto non ho idea di cosa fare. Grazie in anticipo!"int non può essere dereferenziato" in 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();
}
}
}
}
Stai cercando di utilizzare un 'int' in cui si prevede un' Integer', 'number' o' 'Object' ... int 'non ha metodi – MadProgrammer