无法解释NullPointerException

Joh*_*ope 3 java nullpointerexception

在下面的代码中,我有一个方法来获得Vector具有相同星座的人.persoane是一个Vector<Persoana>.我一直NullPointerException在if条件(persoane绝对不是null).我无法理解为什么.任何帮助将不胜感激

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;
}
Run Code Online (Sandbox Code Playgroud)

Pet*_*ang 5

NullPointerException当你试图调用一个方法时,就会发生Object这种情况null.

这意味着以下返回之一null:

  • get(i)
  • getData()
  • getZodie()

逐个添加它们以找出导致异常的实际原因.