hello i create a code in NetBeans by java and i have this error Exception in thr
ID: 3716167 • Letter: H
Question
hello
i create a code in NetBeans by java
and i have this error
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 8
pointer in this method:
public boolean placeOrder(String customerID, String[] itemID, int[] q, String c) {
boolean isPlacedSuccessfuly = true;//flag to indicate that whether the order is placed or not
//looking for the customer who made this order using customer id
Customer customer = null;
boolean tt = true;
while(tt){
for (int i = 0; i < numOfCustomers; i++) {
if (customerID.equals(cList[i].getID())) {
customer = cList[i]; //customer found
tt=false;
}}
}
String orderId = "order"+ customer.getNumOfOrders();//++cus.
//create the order object and pass the data to
Order order = new Order(orderId, new Date(), itemID.length, c);
//add items to the order itemsList array
for (int i = 0; i < itemID.length; i++) {
if (itemID[i] != null) {
//search devices array to find the item by id to get price
double price;
TechnicalDevice device;
for (int j = 0; j < numOfItems; j++) {
device = has[j];
if (device != null) {
if (device.getItemID().equals(itemID[i])) {
if (device.isAvaiable()) {
if (device.getQuantity() >= q[i]) {
price = device.getPrice();
ItemOrder itemOrder = new ItemOrder(itemID[i], q[i], price);
boolean isItemAdded = order.addItemOrder(itemOrder);
if (isItemAdded) {
//remove items from the store by the number of quantity of this device
for (int k = 0; k < q[i]; k++) {
itemOrder.removeItem(has);//pass the array to update
}
//track the item if it's added by any flag you'd like
//I will make the string of the id null to use it later to track the items
//that not added to this order
//remove itemId from itemID list
itemID[i] = null;//flag to indicate that the item is added and removed from the list
}
} else {
isPlacedSuccessfuly = false;//Quantity not available
}
} else {
isPlacedSuccessfuly = false;//device not available
}
}
}
}
}
}//end loop through items
if (isPlacedSuccessfuly) {
customer.confirmed = order;//set current order for the customer to this order
} else {
//reset the number of orders
customer.numOfOrders--;
}
System.out.println(customer.numOfOrders);
return isPlacedSuccessfuly;//process complete
}//end of placeOrder
Explanation / Answer
for (int j = 0; j < numOfItems; j++) {
device = has[j];
As, i dont't know what is there in has array and how long it is.. so it probably is due to the above piece of the code.. But stil Please share your complete code through your g drive by a public document and i will figure out the element causing issues and then tell you. Also, when you get the error, then there will be some line number reported which has caused the issue.. if you can give that.. then it will be very helpful.. (Please provide complete code too)
Thanks! I am working from India, so may be responses can get late.. by i am available for 3 hours from now.. Please do comment and i will help surely.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.