Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 866965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:53:50+00:00 2026-05-15T09:53:50+00:00

I have some code which gets child items for a menu via the GetChildren

  • 0

I have some code which gets child items for a menu via the GetChildren function which takes a list of menuData:

Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))

For Each menuData As MenuData In builtMenu
             If menuData.Children IsNot Nothing Then
            menuData.Children.AddRange(GetChildren(menuData))
             End If
        Next

If I check if menudata.children isnot nothing, it always is nothing because the GetChildren function is yet to run (providing the child items, which do exist). If I remove this check and just have this code:

Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))

For Each menuData As MenuData In builtMenu  
            menuData.Children.AddRange(GetChildren(menuData)) 
        Next

Then I am presented with a Object reference not set to an instance of an object error on menuData.Children.AddRange(GetChildren(menuData))

Please can you tell me how I get around this problem?
Thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:53:51+00:00Added an answer on May 15, 2026 at 9:53 am

    Your menuData.Children has never been instantiated, so it is a null (Nothing) reference.

    You need to instantiate it before you use it:

    Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))
    menuData.Children = New List(Of MenuData)
    
    For Each menuData As MenuData In builtMenu  
        menuData.Children.AddRange(GetChildren(menuData)) 
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code which takes strings representing hexadecimal numbers - hex colors, actually
We have some code which sorts a list of addresses based on the distance
Let's say I have this code which gets the latest posts via ajax: $.ajax({
I have some code which gets resources as follows: public static final String CONVERTER_FILE
I have some code which I want to document with in-body comments like so:
I have some code which I'm currently using to change the static-IP of a
I have some code which populates a hashtable with a question as the key
I have some code which handles data files and reports an error when it
I have some code which is built both on Windows and Linux. Linux at
I have some code which builds an array of date ranges. I then call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.