error when loading the drop down list...

  • Thread starter Thread starter zoneal
  • Start date Start date
Z

zoneal

pls let me know where i am going wrong.

Dim categories As ArrayList

Private Sub LoadCategoryDropDownList()
Dim sCat As String
For Each sCat In categories ///pls see the error at the bottom of the
page.
ddlcat.Items.Add(sCat)
Next
End Sub



Public Shared Function GetCategories() As ArrayList
Dim stream As New FileStream("C:\saru\Categories.dat", FileMode.Open,
FileAccess.Read)

Dim reader As New BinaryReader(stream)
Dim sCat As String
Dim categories As ArrayList

Do Until reader.PeekChar <> -1
sCat = reader.ReadString
categories.Add(sCat)
Loop

reader.Close()
'categories.Sort() /// this line also i am getting error.
Return categories
End Function



Error:



Server Error in '/HalloweenStore' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:

Line 58: Private Sub LoadCategoryDropDownList()Line 59: Dim
sCat As StringLine 60: For Each sCat In categoriesLine 61:
ddlcat.Items.Add(sCat)Line 62: Next


Source File: c:\inetpub\wwwroot\HalloweenStore\Order.aspx.vb Line:
60



Thanks
 
You are not creating a new instace of the list. You have to do something
like "New ArrayList()".
 
Back
Top