- Home /
NullReferenceException when adding String to list
Hey guys! I have a List of strings which i call "data", and i have a string that i call "hint". I am trying to verify if data DOESN'T contain hint so i can add it to the list, but i am getting that boring NullReferenceException on this part of the code:
if (!data.Contains(hint)) // <- THIS PART (LINE 27)
{
data.Add(hint);
}
What may be wrong? If i had any hint (good old irony) of what was happening i would fix it, but instead i just get this error....
Answer by hexagonius · Jun 08, 2017 at 07:28 PM
Well data is null. Wherever you declared it, you didn't assign it a new List
I am 100% sure i saved the script, but for some reason i just reopened it and realised it wasn't there. Strange! Anyway, tnks, that was the problem.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How to Convert FileInfo to TextAsset to add to List 1 Answer
Random role assigning from string array 1 Answer