Last post Aug 29, 2008 01:54 PM by .netBeginner
Aug 29, 2008 01:27 PM|.netBeginner|LINK
I have an arraylist which holds class objects , how I retrieve the object from the class ?
here is my code.
dim updateitem as class2
UpdateItem = cart2.Item(i)
Here cart2 is the arraylist. I am not able to assign the first class object, which is also of the type class2 , to updateitem.
I get the following error, when i come upon the third line:
System.NullReferenceException: Object reference not set to an instance of an object.
Can anyone tell me how to go about this?.Thank You.
Aug 29, 2008 01:42 PM|Jeev|LINK
first of all make sure cart2 is not null and there is an item at i
if i <cart2.count andalso cart2.item(i) isnot nothing then
updateitem = Trycast(cart2.Item(i),class2)
Aug 29, 2008 01:54 PM|.netBeginner|LINK
hi thanks a lot for your help. I found out the error. I am taking the value of the arryalist from t a session object of the same type. Since I intialized cart2 to the session value within if not(ispostback) , everytime the page reloads, I lose cart2's
value when the page reloads.
I corrected the error by initializing it outside the if statement.