[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?
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:
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
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:
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.