Java – cannot interpret NullPointerException
•
Java
In the following code, I have a method to get the vector of people with the same constellation Persoane is vector < persoana > I always get a NullPointerException under the if condition (persoane is definitely not null) I can't understand why Any help would be 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; }
Solution
NullPointerException occurs when you try to call a null method on an object
This means that one of the following returns null:
>Get (I) > getdata() > getzodie()
Add them one by one to find out the actual cause of the exception
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码