Glide TapEvent throwing System.NullException

 public static void Main()
        {
            window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.window_xml));

            GlideTouch.Initialize();

            btn = (GHI.Glide.UI.Button)window.GetChildByName("instance115");

            btn.TapEvent += OnTap;
       

            textBlock = (TextBlock)window.GetChildByName("instance1325");
            

            // write your code here
            com1.DataReceived += new SerialDataReceivedEventHandler(Scale_DataReceived);
            com1.Open();

            TareScale();
            Timer myTimer = new Timer(new TimerCallback(ReadScale), null, 5000, 100);

            Glide.MainWindow = window;
         
            Thread.Sleep(Timeout.Infinite);
        }

This is part of my code, when it gets to btn.TapEvent += OnTap; it throws an exception. This is exactly as the example Glide code.Using NETMF 4.3 on G120E development board.

Thanks for the help.

Where is your OnTap method?

what kind of an exception? null exception?

Sorry!! Here is the code with the OnTap method.

 
        private static Window window;
        private static TextBlock textBlock;
        private static GHI.Glide.UI.Button btn;

        public static void Main()
        {
            window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.window_xml));

            GlideTouch.Initialize();

            btn = (GHI.Glide.UI.Button)window.GetChildByName("instance115");

            btn.TapEvent += OnTap;
       

            textBlock = (TextBlock)window.GetChildByName("instance1325");
            

            // write your code here
            com1.DataReceived += new SerialDataReceivedEventHandler(Scale_DataReceived);
            com1.Open();

            TareScale();
            Timer myTimer = new Timer(new TimerCallback(ReadScale), null, 5000, 100);

            Glide.MainWindow = window;
         
            Thread.Sleep(Timeout.Infinite);
        }

        private static void OnTap(object sender)
        {
            TareScale();
           
        }

On the output window:

[quote] #### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (1) ####
#### Message:
#### MFConsoleApplication4.Program::Main [IP: 0030] ####
Exception thrown: ‘System.NullReferenceException’ in MFConsoleApplication4.exe
An unhandled exception of type ‘System.NullReferenceException’ occurred in MFConsoleApplication4.exe[/quote]



Looks like you are not finding a button with the name "instance115". Check the button name in the XML text,

If you single step your code past this line and then check btn you will see if this is the one that is failing. Single stepping your code is one the great things about debugging NETMF.


btn = (GHI.Glide.UI.Button)window.GetChildByName("instance115");

Also, in your XML give your items a name that is easier to work with instead of the defaults such as instance115.

1 Like

I got confused about the name. :wall: Noob mistake I believe… THANKS!!