Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7704779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:45:27+00:00 2026-05-31T23:45:27+00:00

I try to refer to an array in the Game1 class by creating an

  • 0

I try to refer to an array in the Game1 class by creating an object of the Game1 class with its definition Game1 gameObject; , its declaration gameObject = new Game1(); in the constructor, and its usage gameObject.tileArray[xInt, yInt].treed = true;.

The game1 class itself remains unchanged in its class code other than some methods and variables. When I try to use this code in the TreeRegion class it gives me “Object reference not set to an instance of an object,” leading me to believe that the game1 class is null somehow.

How might one change the class or object in order to refer to game1’s variables? Mind you I am self-taught and still rather new to C#.

The class that refers to game1:
http://pastebin.com/0chEcKfq
Game1 itself
http://pastebin.com/zLDVzCca

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:45:29+00:00Added an answer on May 31, 2026 at 11:45 pm

    When I try to use this code in the TreeRegion class it gives me “Object reference not set to an instance of an object,” leading me to believe that the game1 class is null somehow.

    Not necessary. Look at your expression:

    gameObject.tileArray[xInt, yInt].treed = true;
    

    That will throw a NullReferenceException if any of these are true:

    • gameObject is null (unlikely, given the code you’ve shown)
    • gameObject.tileArray is null
    • gameObject.tileArray[xInt, yInt] is null

    You haven’t shown us the Game1 class – it seems very likely that either the second or third bullet is the problem here.

    You should probably consider whether this should actually be part of the Game1 API rather than digging down the level like this:

    game1.MakeTree(xInt, yInt);
    

    … or whatever the better name might be. It certainly looks like you’re missing some encapsulation here.

    (Personally I wouldn’t really recommend learning C# via something like XNA. I think while you’re still at the stage of learning the language and core libraries, it’s a better idea to work in a simple environment such as console applications. I realize they may seem boring, but a bit of groundwork up-front may make a huge different in the long run.)

    EDIT: Now we can see Game1 (which could do with a new name – and you should try to follow the .NET naming conventions) I strongly suspect that createTiles is causing the problem. It’s not at all obvious that that will actually populate every element of tileArray – particularly as you never even use a or b. My guess is that gameObject.tileArray[xInt, yInt] is returning null in your TreeRegion code.

    EDIT: Looking at how you’re creating the array, it’s even more concerning:

    gridWidth = 100; gridHeight = 100;
    gridScope = gridWidth * gridHeight;
    tileArray = new Tile[gridScope, gridScope];
    

    Did you really want a 10000×10000 array? Are you sure you need this gridScope? I would have expected:

    tileArray = new Tile[gridWidth, gridHeight];
    

    Note that in createTiles you’re only populating at most gridHeight * gridWidth elements (i.e. ten thousand out of the ten million elements in the array).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to refer with an xsd:keyref from within a node/subnode structure to a
I have some cleanup code which may try to refer to an (stateful) EJB
Try as I might I cannot get my head around what the IteratorIterator class
Try to see which cast is faster (not necessary better): new c++ case or
I try to install this phonegap plugin from github , but when I refer
Suppose I need to refer to the path C:\meshes\as . If I try writing
Refer below code public void acquire(){ synchronized(a){ print(acquire()); try{ //Thread.sleep(5000); synchronized(this){ wait(5000); } print(I
This is the code (refer to CODE) I use when I try to create
I want to download image from internet :: I refer this and try this
I'm getting error when i try to refer index with string The error: Notice:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.