Please help I have a problem with the code below it says : Exception in thread “main” java.lang.NullPointerException
import java.util.ArrayList; import java.util.Scanner;
public class AddressBookTest {
ArrayList<AddressBook> ABEntry = new ArrayList<>(100);
public static void main(String[] args) {
AddressBook ABEntry[] = new AddressBook[100]; System.out.println("***PROGRAM INFORMATION*** \nNAME" + "-> IS THE NAME OF THE PERSON IN THE ADDRESSBOOK \nADDRESS" + "-> THE ADDRESS OF THE PERSON \nMOBILE NUMBER" + "-> THE MOBILE NUMBER OF THE PERSON \nEMAIL ADDRESS" + "-> THE EMAIL ADDRESS OF THE PERSON"); String input; Scanner in = new Scanner(System.in); AddressBook details = new AddressBook(); boolean stop = false; do { System.out.println("\nMain Menu"); System.out.println("1. Add an Entry"); System.out.println("2. Delete an Entry"); System.out.println("3. View All Entries"); System.out.println("4. Update an Entry"); System.out.println("5. Exit"); System.out.print("Please enter Choices from 1 to 5: "); input =(in.next()); switch (input) { case "1": System.out.println("==Adding Entry==="); System.out.print("Name: "); details.setName(in.next()); System.out.print("Address: "); details.setAddress(in.next()); System.out.print("Mobile Number: "); details.setMobileNumber(in.nextInt()); System.out.print("Email Address: "); details.setEmailAddress(in.next()+ "\n"); ABEntry[AddressBook.getABCount()] = (details); System.out.println("===Added New Entry==="); break; case "2": //not yet coded //System.out.println("Enter the index of the entry, which you want to delete:"); //AB.remove(in.nextInt()); break; case "3": if (AddressBook.getABCount()==0) System.out.println("===No Entries==="); else System.out.println("===Your Entries==="); for (int i =0; i <ABEntry.length; i++){ System.out.println("Name: " + ABEntry[i].getName() + "\nAddress: " + ABEntry[i].getAddress()+ "\nMobile Number: " + ABEntry[i].getMobileNumber()+"\nEmail Address: " + ABEntry[i].getEmailAddress()+"==================="); } break; case "4": //System.out.println("Enter the index of the entry, which you want to update:"); //get entry at the given index //AddressBook entryToUpdate = addressBook.get(in.nextInt()); /*System.out.print("First Name (current: " + entryToUpdate.getName() + "):"); entryToUpdate.setName(in.next()); System.out.print("Address: (current: " + entryToUpdate.getAddress() + "):"); entryToUpdate.setAddress(in.next()); System.out.print("Mobile Number: (current: " + entryToUpdate.getMobileNumber() + "):"); entryToUpdate.setMobileNumber(in.nextInt()); System.out.print("Email Address: (current: " + entryToUpdate.getEmailAddress() + "):"); entryToUpdate.setEmailAddress(in.next());*/ break; default: break; } //execute while stop is false } while (!input.equals("5")); System.out.println("***THANK YOU FOR USING MY PROGRAM...***");
} }