Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 jclose, Today, 09:37 PM
        0 responses
        5 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,414 views
        0 likes
        Last Post Traderontheroad  
        Started by firefoxforum12, Today, 08:53 PM
        0 responses
        11 views
        0 likes
        Last Post firefoxforum12  
        Started by stafe, Today, 08:34 PM
        0 responses
        11 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by sastrades, 01-31-2024, 10:19 PM
        11 responses
        169 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X