Я хочу удалить экземпляр объекта с именем Entry, если его переменная поля фамилии = фамилия параметра метода. Это то, что у меня есть:
public class ArrayDirectory implements Directory {
public Entry[] records_array = new Entry[100];
List<Entry> record_list = new ArrayList<Entry>(Arrays.asList(records_array));
public static void main(String[] args){
ArrayDirectory newArrayDirectory = new ArrayDirectory();
Entry a = new Entry("Alexander" , "H.A", "53454");
Entry b = new Entry("Hughes","H.H", "12234" );
Entry c = new Entry("Brown" , "L.B", "47665");
Entry d = new Entry("Jenkins", "A.J", "34456");
Entry e = new Entry("Cole", "P.C","57811");
newArrayDirectory.insertEntry(a);
newArrayDirectory.insertEntry(b);
newArrayDirectory.insertEntry(c);
newArrayDirectory.insertEntry(d);
newArrayDirectory.insertEntry(e);
newArrayDirectory.deleteEntryUsingName("Alexander");
}
public void deleteEntryUsingName(String surname) {
// turns records array into ArrayList
Predicate<Entry> condition = Entry -> Entry.getSurname().contains(surname);
record_list.removeIf(condition);
records_array = record_list.toArray(records_array);// turns record_list back into an array
System.out.print(Arrays.toString(records_array));
}
}
Я продолжаю получать исключение нулевого указателя в главном классе, где вызывается метод, и я не знаю, что это значит, если честно.
Вот класс Справочника:
import java.util.List;
public interface Directory {
/**
* Insert a new entry into the directory.
*
* @param entry the new entry to add
*/
public void insertEntry(Entry entry);
/**
* Remove an entry from the directory using their surname.
*
* @param surname the surname of the entry to remove
*/
public void deleteEntryUsingName(String surname);
/**
* Remove an entry from the directory using their extension number.
*
* @param number the extension number of the entry to remove
*/
public void deleteEntryUsingExtension(String number);
/**
* Update an entry's extension number using their surname.
*
* @param surname surname of the entry to be updated
* @param newNumber the new number
*/
public void updateExtensionUsingName(String surname, String newNumber);
/**
* Get the extension number of an entry using their surname.
*
* @param surname the surname of the entry
* @return the extension number of the entry
*/
public String lookupExtension(String surname);
/**
* Return an array list of all entries in the directory.
*
* @return an array list of all entries
*/
public List<Entry> toArrayList();
}