Please help me explaning this. I can’t seem to figure out why this produce a null pointer exception
/* Try to find customer in customer list, if not in list add to list with a
new plan; otherwise add additional plan to customer*/
for(int a = 0; a < dataset.length; a++){
if(customer_name_list.contains(dataset[a][CLIENT_NAME])){
int temp_index = 0;
//NULLPOINTEREXCEPTION OCCURRED ON THE FOLLOWING LINE
while(!customer.get(temp_index).name.equals(dataset[a][CLIENT_NAME])){
temp_index++;
}
customer.get(temp_index).add_plan(dataset[a][PLAN], dataset[a][DETAIL]);
}
else{
Customer temp_customer = new Customer(dataset[a][CLIENT_NAME], dataset[a][PLAN], dataset[a][DETAIL]);
customer.add(temp_customer);
customer_name_list.add(dataset[a][CLIENT_NAME]);
}
}
Thank you for your help
Taking this as the line the exception occurs on:
There’s a number of things that could be calling the issue. First off,
customercould be null. Second, the results ofcustomer.get(temp_index)could be null. Finally,customer.get(temp_index).namecould also be null.Since we’re not working with the full code set here, I suggest you step through and print out the values to each of the above things to work out what one’s null (or use a debugger.) That way you’ll be able to see exactly what’s causing the exception. My guess is that a customer’s name may well be set to null which would cause the issue, but it could just as easily be any of the other things I mentioned.