Results 1 to 2 of 2

Thread: error: Object reference not set to an instance of an object.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    error: Object reference not set to an instance of an object.

    Hello,

    I'm trying to make a map editor so I need to give my map data. But when I try to read/write the data I'll get an error
    "Object reference not set to an instance of an object." I won't get a message box what tells me '1'.

    Code:
        Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click
            Dim m As New Map
            m.Layer.Ground.Tile(5, 5).Data = 1
            MsgBox(m.Layer.Ground.Tile(5, 5).Data.ToString)
        End Sub
    Code:
    Public Class Map
    
        Public Layer As Layerrec
    
        Public Structure Layerrec
    
            Public Ground As Layer
    
        End Structure
    
    
    End Class
    Code:
    Public Class Layer
    
        Public Tile(10, 10) As Tile
    
    End Class
    Code:
    Public Class Tile
    
        Public Data As Integer
    
    
    End Class
    what am I doing wrong?

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: error: Object reference not set to an instance of an object.

    Your classes don't make any sense at all. In Map you have a circular definition and a structure that consists of only one variable. In Tile you have a single variable but everywhere else refer to Tile as defined by two parameters. And what's happening in Layer is beyond me entirely. With the best will in the world you really don't know what you're doing, do you? This may help http://www.homeandlearn.co.uk/net/nets11p5.html although I suspect that you actually need a much more thorough grounding in the use of classes altogether.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width