- Home /
add items to a list
What am I doing wrong? Trying to grab all texture names in a list and add to another string list
if(clothes.accessories.Count > 0) {
var closet : List.<String>;
for (var tex : Texture in clothes.accessories) closet.Add(tex.name); print(closet);
//etc }
I' getting an error message specifically for closet.Add(tex.name);
NullReferenceException: Object reference not set to an instance of an object
The list is not initialized and you're trying to put the elements into a list that does not exist in general. So you have to create a a space for the actual contents to be put in. You can do it as follows.
var closet : List. = new List.();
Let me know if it works out for you.
Answer by gibbie_learnersedge · Sep 21, 2016 at 01:36 PM
Try this. This is in C#
foreach(string tempCloset in closet){
Debug.Log( tempCloset);
}
As iamsidv says, closet
isn't initialised, so this isn't going to help (even if it were in US).
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
C# ArrayList match to string? 1 Answer
Help with Lists and SelectionGrid 1 Answer
How do I find if a string from list was used and exclude it from further use. 1 Answer
Inbox system 0 Answers