locked
Accessing ArrayList RRS feed

  • Question

  • User1030888355 posted

    Hi ,

     

    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  = New 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.

     

     

    Friday, August 29, 2008 1:27 PM

All replies

  • User-125547262 posted

     first of all make sure cart2 is not null and there is an item at i

    dim updateitem as class2 

    if i <cart2.count andalso cart2.item(i) isnot nothing  then

     

    updateitem = Trycast(cart2.Item(i),class2)

    end if

     

    Friday, August 29, 2008 1:42 PM
  • User1030888355 posted

    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.

    Friday, August 29, 2008 1:54 PM