Results 1 to 3 of 3

Thread: [2005] Null Pointer Exception Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    [2005] Null Pointer Exception Help

    Code:
    For row = 0 To 3
         For col = 0 To 4
              Dim curLabel As New Label
               curLabel = Me.TableLayoutPanel1.GetControlFromPosition(row, col)
               With curLabel
                   If sourceIndex >= sourceArray.Length Then
                         .Text = sourceArray(sourceIndex)
                        .Font = My.Settings.myFont
                        .ForeColor = My.Settings.myForeColor
                        .BackColor = My.Settings.myBackColor
                     End If
                End With
                sourceIndex = sourceIndex + 1
        Next
    Next
    I believe sourceArray(sourceIndex) does contain text but that is the line I am getting the NullPointerException?

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Null Pointer Exception Help

    Quote Originally Posted by jeffnyc
    I believe sourceArray(sourceIndex) does contain text but that is the line I am getting the NullPointerException?
    That's definitely not good enough. Step through the code and actually see what sourceArray contains at that point.


    My guess is that your Array definition looks something like this and this is causing the exception.
    VB.NET Code:
    1. Dim sourceArray() As String
    If you are going to dynamically add items to a collection like that, then use a Generic List instead: http://msdn2.microsoft.com/en-us/lib...19(vs.80).aspx

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Re: [2005] Null Pointer Exception Help

    Quote Originally Posted by nmadd
    That's definitely not good enough. Step through the code and actually see what sourceArray contains at that point.


    My guess is that your Array definition looks something like this and this is causing the exception.
    VB.NET Code:
    1. Dim sourceArray() As String
    If you are going to dynamically add items to a collection like that, then use a Generic List instead: http://msdn2.microsoft.com/en-us/lib...19(vs.80).aspx

    I dim the array as object type. Also, I need to specify col before row.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width