0

can someone help me with this issue i don't see why its not initializing but here is my error:

Object reference not set to an instance of an object.

And Here is My Code:

Dim pic As New PictureBox
    Dim frm As New Form
    Public lbllist As Generic.List(Of Label)
    Public piclist As New Generic.List(Of PictureBox)
    Public txtbox As Generic.List(Of TextBox)
    Private index As Integer

Sub AddLabel(ByVal label_index As Long, ByVal caption As String, ByVal left As Integer, ByVal top As Integer, ByVal customsize As Integer, ByVal customcolor As Integer, ByVal alignment As Byte, ByVal width As Long, ByVal height As Long)
        Dim lblboxer As New Label
        lblboxer.Text = caption
        lblboxer.Left = left
        lblboxer.Top = top
        lblboxer.Font = New Font(lblboxer.Font.FontFamily, customsize)
        lblboxer.ForeColor = Color.Yellow
        lblboxer.TextAlign = ContentAlignment.MiddleCenter
        lblboxer.Width = width
        lblboxer.Height = height
        lbllist.Add(lblboxer)
        frm.Controls.Add(lbllist.Item(label_index))
        AddHandler lbllist.Item(label_index).Click, AddressOf label_Click
    End Sub

and this is what is not initializing for some strange reason in that code(above):

piclist.Add(Picboxer)

Thanks in return,
Stormshell

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Arunabh Nag
0

remove the New from the declaration and inititialise the generic list on load or whenever you start needing it.
btw i cant find piclist.Add(Picboxer) in the code you have posted o.O

0

>Object reference not set to an instance of an object.
Error describes that you are working on null. Take look into your code and find where you missed New keyword.

0

U missed new here ::

Dim pic As New PictureBox
    Dim frm As New Form
    Public lbllist As Generic.List(Of Label) 'Insert new here
    Public piclist As New Generic.List(Of PictureBox)
    Public txtbox As Generic.List(Of TextBox)
    Private index As Integer
 
Sub AddLabel(ByVal label_index As Long, ByVal caption As String, ByVal left As Integer, ByVal top As Integer, ByVal customsize As Integer, ByVal customcolor As Integer, ByVal alignment As Byte, ByVal width As Long, ByVal height As Long)
        Dim lblboxer As New Label
        lblboxer.Text = caption
        lblboxer.Left = left
        lblboxer.Top = top
        lblboxer.Font = New Font(lblboxer.Font.FontFamily, customsize)
        lblboxer.ForeColor = Color.Yellow
        lblboxer.TextAlign = ContentAlignment.MiddleCenter
        lblboxer.Width = width
        lblboxer.Height = height
        lbllist.Add(lblboxer)
        frm.Controls.Add(lbllist.Item(label_index))
        AddHandler lbllist.Item(label_index).Click, AddressOf label_Click
    End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.