0
sub main()
dim menuhistory as stack(of menu)
dim currentmenu as menu  
dim apple as new menu("fruit")  
currentmenu = apple  
menuhistory.push(currentmenu)
public class menu
    menutext as string
    Public Sub New(ByVal input As String)
      menutext = input
    End Sub
end class
end sub

I'm trying to create a stack of menus so I can navigate forward and back between different menus, however when I get down the push line to push my menu onto the stack I get the following error: "NullReferenceException was unhandled: Object reference not set to an instance of an object.". I'm unsure what the problem is as I am trying to push an object onto my stack, a menu object. The same error occurs even if I change the object I am trying to push directly to apple as well.

Any help would be greatly appreciated.

Peter Benson
  • 15
  • 1
  • 5

1 Answers1

2

To create a new Stack object, you'll have to use New keyword.

Try

dim menuhistory as New Stack(Of menu)
Bala R
  • 107,317
  • 23
  • 199
  • 210