1
Public Overridable Sub printMatrix()
    administrator.ListBox1.Items.Add(ControlChars.Lf)
    For i As Integer = 1 To matrix.Length - 1
        For j As Integer = 1 To matrix.Length - 1
            Dim parser() As String = matrix(i)(j).Split(New Char() {" "c})
            ' Dim parser() As String = matrix(i)(j).Split(" ", True)
            For k As Integer = 0 To parser.Length - 1
                If Regex.IsMatch(parser(k), "[a-zA-Z ]*\d+.*") Then
                    Console.Write(Double.Parse(parser(k)) & " ")
                End If
                'If parser(k).matches("[a-zA-Z ]*\d+.*") Then
                '    Console.Write(Double.Parse(parser(k)) & " ")
                'End If
            Next k
            administrator.ListBox1.Items.Add("|" & ControlChars.Tab)
        Next j
        administrator.ListBox1.Items.Add(ControlChars.Lf)
    Next i
End Sub

Getting a NullReferenceException on Split String error when running program. Sorry, new here. I'm parsing through an array and trying to print the values to a listbox. The original code was written in Java and after using a converter to add it to my vb.net code I'm getting this null exception.

Error Message

T.S.
  • 18,195
  • 11
  • 58
  • 78
  • Copy/paste the relevant code into your question, don't take a screenshot of it. – Jimmy M. Dec 05 '16 at 03:44
  • Make sure code is an SSCCE: http://sscce.org/ - regardless, you have a `null`. Why? What expectation did not hold? And *why* is this tagged "Java" **and** "VB.Net"? – user2864740 Dec 05 '16 at 03:44
  • 2
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – user2864740 Dec 05 '16 at 03:45
  • `matrix(i)(j)` is nothing. Use `IF` block to prevent error – T.S. Dec 05 '16 at 03:59

1 Answers1

0

Try this:

 Dim parser As new String() = matrix(i)(j).Split(New Char() {" "c})
3vts
  • 778
  • 1
  • 12
  • 25