I have an abstract class that has heirs. In the heirs I read data from external files in class constructors - the operation is the same for all heirs. I decided to implement reading in the class of the parent. As a result, I get the error "NullPointerException" This is how it is implemented in the parent class.
public abstract class Parent { private ArrayList<Campaign> listOfCampaigns; private ArrayList<Campaign> filteredCampaigns; private String[] campaignsPath; Parent(){ super(); listOfCampaigns = readListOfCampaigns(campaignsPath); // считывание } public double find(Request request){ // Первичная фильтрация filteredCampaigns = filterCampaigns(listOfCampaigns, request); return 1; } protected ArrayList<Campaign> filterCampaigns (ArrayList<Campaign> totalListOfCampaigns, Request request){ for ( int i = 0; i < totalListOfCampaigns.size(); i++ ){ // Вот и вылезает ошибка NullPointerException ... ... } } }
Why the error gets out?
filterCampaigns
method if (totalListOfCampaigns == null) throw new Exception (); (temporarily, for debugging). If you really do not passnull
, it does not hurt. - VladD