"Object reference not set to an instance of an object"

  • Thread starter Thread starter Rock
  • Start date Start date
R

Rock

I am getting the above error on If arrFields is nothing or
arrFields.Count=0, I don't understand why I am getting the error:

dim arrFields as new ArrayList
arrFields = CType(ViewState("arrFields"), ArrayList)
--this is where I get the error:
If arrFields is nothing or arrFields.Count=0 then
Call GetFields
ViewState("arrFields") = arrFields
end if
End If

Does anyone know why I would be getting this error, when in fact the object
is set?
 
Not sure, it seems like the object should be there.

Try using If arrFields is nothing OrElse arrFields.Count=0 then, in stead of
just Or and see if it makes a difference...
 
Rock said:
I am getting the above error on If arrFields is nothing or
arrFields.Count=0, I don't understand why I am getting the error:

dim arrFields as new ArrayList
arrFields = CType(ViewState("arrFields"), ArrayList)
--this is where I get the error:
If arrFields is nothing or arrFields.Count=0 then
Call GetFields
ViewState("arrFields") = arrFields
end if
End If

Does anyone know why I would be getting this error, when in fact the object
is set?
When I store things in viewstate, I always check for the ViewState being
nothing before I access it. Try adding
If not ViewState("arrFields") is nothing then ....
Mike
 
vb does not shortcut ifs, so if arrField is nothing, you will get an error
on the "or arrFields.Count=0" clause, which will happen if the object is
not in the viewstate.

-- bruce (sqlwork.com)


| I am getting the above error on If arrFields is nothing or
| arrFields.Count=0, I don't understand why I am getting the error:
|
| dim arrFields as new ArrayList
| arrFields = CType(ViewState("arrFields"), ArrayList)
| --this is where I get the error:
| If arrFields is nothing or arrFields.Count=0 then
| Call GetFields
| ViewState("arrFields") = arrFields
| end if
| End If
|
| Does anyone know why I would be getting this error, when in fact the
object
| is set?
|
|
 
Thanks. The OrElse worked, and so does checking the viewstate first. I
will keep this in mind, I now understand why it happened. Thanks all!
 
Back
Top