runtime error - Object reference not set to an instance of an object - C# -


i'm beginner c# , keep getting 'system.nullreferenceexception' error. i've looked everywhere can't seem find useful solution. simplified code below more clear.

namespace tile_test {     public class game1 : game     {         public static float bottomworld = 38400f;         public static float rightworld = 134400f;         public static int maxtilesx = (int)rightworld / 16 + 1;         public static int maxtilesy = (int)bottomworld / 16 + 1;           public game1()         {             tile[,] tile = new tile[maxtilesx, maxtilesy];             int x = 1;             int y = 1;             tile[x, y].active = false; //error on line.         }     } } 

the tile-class shown below

namespace tile_test {     public class tile     {         public bool active;     } } 

could me out?

you have declared array store tile objects dimensions needed, every single slot of array null, can't reference null trying assign property active

tile[,] tile = new tile[maxtilesx, maxtilesy]; int x = 1; int y = 1; tile[x, y] = new tile() {active=false}; 

and need code every tile plan store in array


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -