Course Solutions Uncategorized (Solved) : Java Won T Arraylist Add First Item Method Using Works Fine First Soon Test Second Item Ar Q35854442 . . . .

(Solved) : Java Won T Arraylist Add First Item Method Using Works Fine First Soon Test Second Item Ar Q35854442 . . . .

 

Java

Why won’t my arrayList add more than the first Item?

Below is the method i am using. It works fine for the first. Butas soon i test it for the second item in the array, it comes backnull.

Thank you in advance

—————————————————————————————————————————————————————————————————————————–

Methods addItem & findItem

public voidaddItem(unisa.library.Item newItem) throwsDuplicateItemException {

unisa.library.Item tempItem;

try {

tempItem = findItem(newItem.ID);

if(tempItem == null) {

itemList.add(newItem);

}

else {

throw newDuplicateItemException(newItem.ID + “already exists”);

}

} catch (ItemNotFoundException e) {

itemList.add(newItem);

}

}

public unisa.library.Item findItem(String id)throws unisa.library.ItemNotFoundException {

//Method used to locate an Item based off the id provided in theparameters

// First find if the list is empty, if it is then throwexception

if(itemList.isEmpty())

throw newItemNotFoundException(id + “Cannot be found”);

try {

//try to locate

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post