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 406929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:32:40+00:00 2026-05-12T17:32:40+00:00

Stack Overflowers: I have been racking my brain trying to get an List(of T)

  • 0

Stack Overflowers:

I have been racking my brain trying to get an List(of T) type array to be the property of a class. I know there has to be a simple way of doing it and I can’t find a good example on google. Everytime I create a class that I think will work I get the “Object reference not set to an instance of an object” error when I try to use it. My thinking now is that I cannot use it in the way I was hoping to. Here is my latest attempt:

Public Class Item
    Private _itemno As String
    Public Property ItemNo() As String
        Get
            Return _itemno
        End Get
        Set(ByVal value As String)
            _itemno = value
        End Set
    End Property
        //Many more properties in here
End Class


Public Class Accessory
    Private _items as List(of Item)
    Public Property Items() As List(of Item)
        Get
            Return _itemno
        End Get
        Set(ByVal value As List(of Item))
            _itemno = value
        End Set
    End Property
End Class

Public Class MasterItem
    Private _item as Item
    Public Property PrimaryItem as Item
        Get
            Return _item
        End Get
        Set(ByVal value As Item)
            _item = value
        End Set
    End Property

    Private _accessories as Accessory
    Public Property Accessories() As Accessory
        Get
            Return _accessories
        End Get
        Set(ByVal value As Accessory)
            _accessories = value
        End Set
    End Property
End Class

I am trying to return the MasterItem class from a test function like this:

Public Shared Function GetItem() as MasterItem
    Dim testItem as new MasterItem

    ReturnItem.PrimaryItem.ItemNo = "TEST123"

    ReturnItem.Accessories.Items.add(New Item("TESTACC1"))
    ReturnItem.Accessories.Items.add(New Item("TESTACC2"))

    Return testItem
End Function

What am I doing wrong here? Thanks in advance.

  • 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-12T17:32:41+00:00Added an answer on May 12, 2026 at 5:32 pm

    You haven’t create an instance of list you are trying to put items to.

    Initialize it in constructor of your Accessory class. Something like

    Public Sub New()
        _items = New List(Of Item)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Esteemed Overflow-ers of the Stack, So I've recently been trying to fully wrap my
Stack Overflowers: I have a search function on my company's website (based on .NET
Hello stack overflowers, I have a desing that uses the flyweight pattern to share
This much I have already cobbled together (thanks to Stack Overflowers): I have a
Hello fellow StackOverflowers. I'm have a brain fart right now, and I cannot seem
Overflowed Stack, I have a Java web application (tomcat) whereby I allow the user
I'm pretty sure someone will have done something like this before but have been
I have a question, which may be a pipe-dream, but I wanted to know
Most of us know that a loop should not have a non-terminating condition. For
I'm working on a school project, and basically we're trying to learn about stack

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.