Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't explain NullPointerException

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;
}
like image 233
John Pope Avatar asked Jul 26 '26 00:07

John Pope


1 Answers

NullPointerException occurs, when you try to call a method on an Object that is null.

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.

like image 99
Peter Lang Avatar answered Jul 27 '26 14:07

Peter Lang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!