Help me with my code!

I get this error from the trace window:

IntelliQueueAdd-initialized-
---- Traces From: d6d91a45-84ee-48f8-802f-3f395427503dTick 1029
System.NullReferenceException: Object reference not set to an instance of an object.
   at VBCreatures.Herbivore1.IntelliQueueEx() in C:\Documents and Settings\Jacob Quinn Shenker\My Documents\Visual Studio Projects\Terrarium\Herbivore1\Class1.vb:line 255-
IntelliQueueEx-initialized-
System.NullReferenceException: Object reference not set to an instance of an object.
   at VBCreatures.Herbivore1.IntelliQueueAdd(Point Dest, Int32 Priority) in C:\Documents and Settings\Jacob Quinn Shenker\My Documents\Visual Studio Projects\Terrarium\Herbivore1\Class1.vb:line 225-
1361-

First of all, I am programming in VB. I have added the WriteTrace(Exc.ToString) Try statement to all my subs and functions to debug them. What does the above error mean

Some Background knowledge:

My sub IntelliQueueEx tries to BeginMoving toward the next point in the Queue. To find the relevant points, it searches through my arraylist MoveQueue filled with points at indexes of 1,2, and 3 only. I thought it might have something to do with comparing point turned into objects with either empty points or null values. Here are my two buggy subs: (don't comment on my comments or the "dirty-ness" of my code and WEIRD variable names, i'm only a beginner)
--------------------------------------------------------------------------------------------------------
Sub IntelliQueueAdd(ByVal Dest As Point, ByVal Priority As Integer) 'Priority key: 1=food 2=escape 3=random
            Try
                WriteTrace("IntelliQueueAdd-initialized")
                Dim Yesseroo = False
                If MoveQueue(Priority).Equals(Point.Empty) = True Then
                    Select Case Priority
                        Case 1
                            If Not IsEating Then
                                WriteTrace("IntelliQueueAdd-eating mvector passed")
                                Yesseroo = True
                            End If
                        Case 2
                            WriteTrace("IntelliQueueAdd-defence mvector passed")
                            Yesseroo = True
                        Case 3
                            If Not IsEating Then
                                WriteTrace("IntelliQueueAdd-random mvector passed")
                                Yesseroo = True
                            End If
                    End Select
                End If
                If Yesseroo = True Then
                    MoveQueue(Priority) = Dest
                End If
            Catch exc As Exception
                ' WriteTrace is useful in debugging creatures
                WriteTrace(exc.ToString())
            End Try
        End Sub
        Sub IntelliQueueEx()
            Try
                WriteTrace("IntelliQueueEx-initialized")
                Dim Priority As Integer = 1
                While MoveQueue(Priority).Equals(Point.Empty)
                    Priority = Priority + 1
                    If Priority >= 4 Then
                        Priority = 0
                        WriteTrace("IntelliQueueEx-no match found")
                        Exit While
                    End If
                End While
                If Not Priority = 0 Then
                    'If State.Position.X = MoveQueue(Priority).X AndAlso State.Position.Y = MoveQueue(Priority).Y Then 'initial move prevents this
                    Dim DestyII As Point
                    DestyII.X = MoveQueue(Priority).X
                    DestyII.Y = MoveQueue(Priority).Y
                    Dim SpeedSelectII As Integer = Species.MaximumSpeed 'IntelliSpeed()
                    BeginMoving(New MovementVector(DestyII, SpeedSelectII))
                    WriteTrace("IntelliQueueEx-begin moving")
                    'MoveQueue(Priority) = Point.Empty
                    'End If
                    WriteTrace("IntelliQueueEx-match found")
                End If
            Catch exc As Exception
                ' WriteTrace is useful in debugging creatures
                WriteTrace(exc.ToString())
            End Try
        End Sub
-----------------------------------------------------------------------------------------------------------

Thank you in advance for helping!


Answer this question

Help me with my code!

  • Ste Moore

    The error message means that on line 255 in Class1.vb you are trying to use a reference to an object that has not been initialized.  The following code snippet will give you the same error.  If you need further assistance, post line 255 of Class1.vb and the function or subroutine that it's in.

    'Declare an object reference
    Dim myVar as AnimalState 

    'Throws an exception because myVar hasn't been set!
    if myVar.GridX < 5 then 
    ...

  • AnotherAlien

    Actually, I just fixed it, whatever it was!
  • Help me with my code!