• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

calling 'OnStateChange' method. Object reference not set to an instance of an object

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    calling 'OnStateChange' method. Object reference not set to an instance of an object

    I have an indicator that works with no issues but on the log and trace I get the error
    Error on calling 'OnStateChange' method. Object reference not set to an instance of an object

    This error is too vague but I Know it is in OnStateChange. I tried to debug it in Visual studio 2017 but I can not get the breakpoints activated to find where the issue is.

    When adding breakpoints The error I get is breakpoints will not be hit. No symbols have been loaded for this document.
    Does anyone know how to fix this in order to use the breakpoints?

    #2
    well I found the issue but I was wondering if there is a better way than just a regular try and catch

    try
    {
    ChartControl.MouseLeftButtonDown -= MouseClicked;
    }
    catch { }

    Comment


      #3
      Lastly if you want to use visual studio 2017 you have to compile in ninjatrader in order for the breakpoints to be recognized

      Comment


        #4
        Hello ballboy11,

        Thank you for the post.

        The error you are getting is a general C# error relating to using an object that is null. You can search online (google) for this error message ( Object reference not set to an instance of an object) to gather further details about it. OnStateChange is simply the location, however, there are multiple states so adding a Print(State) at the beginning of OnStateChange can help debug this type of situation.

        You have likely used ChartControl either in a state where it cannot be used, or the script is being used in a use case where ChartControl is not present. The solution is to just check if the object is null. I would never suggest using try/catch for general purpose cases like this I would only suggest using try/catch for targeted debugging when you know what exception should be raised.

        Code:
        if(ChartControl != null)
        {
           //do the logic here
        }

        In regard to visual studio, that would be correct, visual studio would require you to compile NinjaTrader in debug mode for breakpoints to be met. We have a guide on debugging with visual studio here: https://ninjatrader.com/support/help...=visual+studio

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by victorsmith, Today, 06:00 AM
        0 responses
        3 views
        0 likes
        Last Post victorsmith  
        Started by sohailashraf, Yesterday, 10:18 PM
        0 responses
        6 views
        0 likes
        Last Post sohailashraf  
        Started by jjnc2006, Yesterday, 07:36 PM
        0 responses
        15 views
        0 likes
        Last Post jjnc2006  
        Started by futurenick, Yesterday, 06:26 AM
        1 response
        15 views
        0 likes
        Last Post nkhoi
        by nkhoi
         
        Started by NinjaCustomer, Yesterday, 12:29 PM
        2 responses
        16 views
        0 likes
        Last Post NinjaCustomer  
        Working...
        X