In the following code, i have a method to get a Vector of persons with the same zodiac sign. persoane is a Vector<Persoana>. I keep getting a NullPointerException at the if condition (persoane is definetly not null). I am unable to see why. Any help would be greatly appreciated
public Vector<Persoana> cautaDupaZodie(String zodie)
{
Vector<Persoana> rezultat= new Vector<Persoana>();
for(int i=0; i<persoane.size(); i++)
{
if(persoane.get(i).getData().getZodie().equals(zodie)) //the exception occurs here
{
rezultat.add(persoane.get(i));
}
}
return rezultat;
}
NullPointerExceptionoccurs, when you try to call a method on anObjectthat isnull.This means that one of the following returns
null:get(i)getData()getZodie()Add them one by one to find out what actually is causing your exception.