I'm trying to debug a program which uses a ListView to create a list of icons for files stored in a DB. I got the log of an exception stating System.nullreferenceexception: 'object reference not set to an instance of an object.'.
What I get specifically from the log file is this
System.nullreferenceexception: object reference not set to an instance of an object.
in System.Windows.Forms.ListViewItem.set_Selected(Boolean value)
in (MyFilesControl , Boolean )
in MyLibrary.MyFilesControl.MyMethod(Boolean MyBooleanVariable)
where MyFilesControl is a custom Control basically used to show a tree view of folders, a file view and other things.
The real problem is that last line in the log seems to imply the error is generated here.
If MyBooleanVariable AndAlso MyListView.Items.Count > 0 AndAlso MyListView.SelectedItems.Count = 0 Then
MyListView.Items(0).Selected = True ' error here, most likely
End If
This implies in that last line of code something should be Nothing... Except in theory it CAN'T be nothing. Right? All 3 conditions right above exist (included MyBooleanVariable, since it's an optional Boolean created and passed by MyMethod).
So my main issue and doubt is: can something be Nothing in that last line of code? I also tried to set the value to Nothing but I get the exception on the new added line, that's why I'm assuming a ListItem cannot be Nothing. Asking also because I'm trying to replicate the exception but I seem uncapable of ever getting it. The code always works for me but still that log exists.
Selectedproperty. That's not a simple property but this. It could be for example a threading issue.