NullPointException on custom built search when query yields no result
22:03 09 Dec 2018

I am building a search for a school project and I have been stuck on this all day. I have tried everything I can think of. I must be missing something simple somewhere, just not sure what at this point.

I am getting the Exception in thread "main" java.lang.NullPointerException at line 56 which is the first IF inside of the FOR loop. This only happens if the search doesnt find anything. Everything else seems to be working fine.

Thanks in advance to anyone who gives this a go.

else if ( menuSelect == 3)
        {
            do
            {
                Display.search(fullLine);
                continueSearch = 1;
                search = input.nextLine();
                if (search.length() == 10 && search.matches(regex))
                {
                    search = search.replaceFirst("(\\d{3})(\\d{3})(\\d+)", "($1) $2-$3"); // format phone number
                } // end IF search match regex (phone format)

                for (int index = 0; index < MAX && continueSearch == 1; index++)
                {
                    if (leadArray[index].getName().equalsIgnoreCase(search)
                            || leadArray[index].getAddress().equalsIgnoreCase(search) 
                            || leadArray[index].getPhone().equalsIgnoreCase(search) 
                            || leadArray[index].getEmail().equalsIgnoreCase(search))
                    {

                        Pages.viewLead(listSize, noteListSize, index, noteArray, leadArray);
                        menuSelect = 0;
                        continueSearch = 0;
                    } // end IF search matches data params
                    else if (leadArray[index].getName().contains(search) 
                            || leadArray[index].getAddress().contains(search) 
                            || leadArray[index].getPhone().contains(search) 
                            || leadArray[index].getEmail().contains(search))
                    {                   
                        Pages.searchAllLeads(listSize, noteListSize, search, noteArray, leadArray);
                        menuSelect = 0;
                        continueSearch = 0;
                    } // end IF search contains data params 
                    else if (search.equals("00"))
                    {
                        continueSearch = 0;
                        Pages.mainMenu(listSize, noteListSize, noteArray, leadArray);
                    } // end IF exit search 00              
                } // end FOR array Loop
                System.out.println("\nYour search returned (0) results.\n");
            } while (!"00".equals(search) ); // end search loop
            Pages.mainMenu(listSize, noteListSize, noteArray, leadArray);
        } // end IF menuSelect 3 (search)
java for-loop nullpointerexception do-while