how to solve this exception
Imports Leo_myfile
Public Class Form1
Inherits System.Windows.Forms.Form
For Each favfile In favfiles.temp <-------- I have a null exception here
Dim item As New ListViewItem
item.Text = favfile.Name
item.SubItems.Add(favfile.size)
lstfile.Items.Add(item)
Next
End Sub
End Class
------------------------------------------------------------------------------------------------------------
imports System.IO
Public Class mywebfile
Public temp As webfilecollection
Dim folder As String = "c:\temp1\"
Public Sub scanfolder()
scanfolder(folder)
End Sub
Public Sub scanfolder(ByVal folder As String)
Dim folders As New DirectoryInfo(folder)
Dim file As FileInfo
For Each file In folders.GetFiles
If String.Compare(file.Extension, ".*", True) = 0 Then
Dim myfile As New webfile
myfile.load(file)
temp.add(myfile)
End If
Next
End Sub
End Class
------------------------------------------------------------------------------------------------------------
Public Class webfilecollection
Inherits CollectionBase
Public Sub add(ByVal favorite As webfile)
list.Add(favorite)
End Sub
Public Sub remove(ByVal index As Integer)
If index >= 0 And index < Count Then
list.Remove(index)
End If
End Sub
Public ReadOnly Property item(ByVal index As Integer) As webfile
Get
Return CType(list.Item(index), webfile)
End Get
End Property
End Class
------------------------------------------------------------------------------------------------------------
mports System.IO
Public Class webfile
Public Name As String
Public size As String
Public Sub load(ByVal fileInfo As FileInfo)
Name = fileInfo.Name
Dim stream As New FileStream(fileInfo.FullName, FileMode.Open)
Dim reader As New StreamReader(stream)
Do While True
Dim buf As String
If buf Is Nothing Then Exit Do
If buf.EndsWith("b") Then
size = buf.Substring(0)
Exit Do
End If
Loop
reader.Close()
stream.Close()
End Sub
End Class
how to solve the null An unhandled exception of type 'System.NullReferenceException' occurred in fileviewer.exe
Additional information: Object reference not set to an instance of an object.
please help me