나는 꽤 Java
에 새로 출연했고 나는 BlueJ
를 사용하고있다. 계속 오류가 발생합니다.클래스의 생성자를 특정 유형에 적용 할 수 없습니다. 도움을 청하십시오.
constructor ItemNotFound in class ItemNotFound cannot be applied to given types;
required: int
found: no arguments
reason: actual and formal arguments lists differ in length
나는 상당히 혼란스럽고 문제를 해결하는 방법을 모릅니다. 잘만되면 누군가 나를 도울 수 있습니다. 미리 감사드립니다.
참고로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 == list[pos].getItemNumber()){
return list[pos];
}
else {
throw new ItemNotFound(); //"new ItemNotFound" is the error
}
}
}
}
, 여기뿐만 아니라 class ItemNotFound
코드입니다 :
// This exception is thrown when searching for an item
// that is not in the catalog.
public class ItemNotFound extends Exception {
public ItemNotFound(int id) {
super(String.format("Item %d was not found.", id));
}
}
다시 방문하십시오. 나는이 질문과 어떻게 관련이 있는지 이해하지 못했다. – SudoRahul
죄송합니다. 실수로 생성자에 int 인수를 전달한다고 생각했습니다. super (String.format ("Item % d을 (를) 찾을 수 없습니다.", id)); 카탈로그 클래스에 있습니다. 사실, 명시 적 생성자 항목 (int id)을 정의 했으므로 new Item()이 유효하지 않습니다. 이전 답변을 무시합니다. –
답변을 수정하여 게시하십시오. 여기 코멘트가 아닙니다. – SudoRahul