Method returning null Class

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Method returning null Class



I think maybe this could be a design problem but I have a problem with a method that should return a specific class that is passed in the method. However, the method should return the modified class but it returns null.


AnimalSummary animalSummary = new AnimalSummary()


for (animal : animals){
animalSummary = new Zoo().calculateAnimalTypeLegs(animal, animalSummary)
}



This is the method


AnimalSummary calculateAnimalTypeLegs(Animal animal, AnimalSummary animalSummary){

if (animal.type.equals("Bear")
animalSummary.setTotalLegs(animalSummary.getTotalLegs()+4)
if (animal.type.equals("Human")
animalSummary.setTotalLegs(animalSummary.getTotalLegs()+2)

return animalSummary



While iterating through all the elements the first class is initialized correctly, but after the first return of the method and the second element the class animalSummary is null.



While debugging the first time the method gets the animalSummary class is correctly initialized. However it is after returning the value and entering in the second iteration that the animalSummary class is null





where you create animalSummary. give more code
– sajib
3 mins ago





Our God of Programming Debuger what say?
– raul1ro
3 mins ago





what exactly are you trying to get
– dangi13
3 mins ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

2kDx6Ojt82HYPWLwbJxsVl 0,futP3 5K7 bpx3RtOn2t5lk,4O 5l y YdKUdOJZGlGvqfy0y38h9cIGVU5MnT IC2Z,kG
sIfDMjHubc X3ZBDxzj

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results