#Calling .add method on a declared ArrayList
4 messages · Page 1 of 1 (latest)
Hey, @feral gale!
Please remember to /close this post once your question has been answered!
your first method threw an error because, as you correctly pointed out, the testingResult variable was null. Now how to prevent this ? Exactly like you did. Either you initialise the variable with a new instance of ArrayList or you assign an existing ArrayList to it. However, I wouldn't actually do this in the method addResult. I would personally create a new ArrayList inside the constructor of the class or directly when declaring the field. Additionally, as kaasadin pointed out you aren't actually adding anything to testingResults in your second method you are adding something (I dont know what because it isnt one of your parameters) to another arraylist called experimentsResult.