Unhandeled exeption of type "System.NullReferenceException" at monitor.Stop() event

4 posts, 0 answers
  1. Dino
    Dino avatar
    3 posts
    Member since:
    Jul 2013

    Posted 31 Aug 2013 Link to this post

    i get this error during the monitor:stop(); event at the application closing, i use the back key press to call this event this is the code i used

    public partial class MainPage : PhoneApplicationPage
        {
            private IAnalyticsMonitor monitor;  

     private void PhoneApplicationPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
            {
                IAnalyticsMonitor monitor = AnalyticsMonitorFactory.CreateMonitor("9A603DCBB60C4F02B30DCAB99AC9D415");

    monitor.Start();
              
            }

    and further down in my code i have this event 


            private void Window_Closed(object sender, CancelEventArgs e)
            {
              monitor.Stop();
            }

    now on the application closing i get this error of "unhandled exception of type "System.NullReferenceException", what am i doing wrong?! and how can this be fixed or handled?

  2. Soren
    Admin
    Soren avatar
    44 posts

    Posted 01 Sep 2013 Link to this post

    Hello Dino,

    Sorry for your troubles. Let me see if I can help you out. Can you start by confirming that the unhandled exception is not caused by the monitor instance being null within your own code? I'm not terribly familiar with the page lifecycle for Phone applications but if the Loaded event is somehow not fired then the Close event will try to reference a null variable. Perhaps you should guard the code in your Close event handler with a null-check and see if that fixes the issue?

    If it does not fix the issue, I'd appreciate a as much of a stacktrace (including inner exceptions) as possible in order to determine where the error may originate.

    Looking forward to hearing from you.
     
    Regards,
    Soren
    Telerik
    JAVASCRIPT MONITOR (BETA) AVAILABLE FOR DOWNLOAD.
    Monitor web applications with the new EQATEC Application Analytics JS library. Compatible with all modern browsers.
    Test it today >>
  3. Dino
    Dino avatar
    3 posts
    Member since:
    Jul 2013

    Posted 03 Sep 2013 Link to this post

    My code is ok if i remove the analytics, and i can start monitor.Start(); directly after the call

     IAnalyticsMonitor monitor = AnalyticsMonitorFactory.CreateMonitor( my key );

    but i can not stop it on the same page with lets say the backbutton exit from the app, or with any other behaviour or method. the problem is i can call monitor.stop(); only in this one method. and if i make an reference on this page to monitor its give me this error above. so the problem is i cant make an reference to use it in the code under this class
  4. Soren
    Admin
    Soren avatar
    44 posts

    Posted 06 Sep 2013 Link to this post

    Hello Dino,

    I think you should look into how you manage the IAnalyticsMonitor instance in your code. Ideally, you should only create and start the instance once for your entire application, which should typically be done in a Main method, a Bootstrapper etc.. Dependent upon your specific architecture, you could e.g. store the created instance in a static variable or somewhere similar.

    The key issue is that the monitor should be created once in your application and all your tracking code should reference this instance. From looking at your sample codes, your issues seems to originate from the fact the your IAnalyticsMonitor instance is not reachable when you need to call start.

    Hope this helps

    Regards,
    Soren
    Telerik
    JAVASCRIPT MONITOR (BETA) AVAILABLE FOR DOWNLOAD.
    Monitor web applications with the new EQATEC Application Analytics JS library. Compatible with all modern browsers.
    Test it today >>
Back to Top