bloukewer
Well-known member
- Joined
- Jul 2, 2004
- Messages
- 88
- Programming Experience
- 3-5
I have a button which executes the following (pseudo) code when clicked:
dim tmp as new employee
tmp.Name = txtName.text
tmp.Surname = txtSurname.text
Arraylist1.add(tmp)
...
'do something that calls each element of Arraylist1
Now, the code executes perfectly the first time. The second time I push the button though, it throws a null-reference exception. Upon evaluation it is evident that the arraylist did not add a new object to the arraylist, but instead just modified tmp and moved it to the next position in the arraylist, leaving the preceding arraylist pointer empty.
Thus, after the second click, arraylist(0) is empty and arraylist(1) contains the new object.
Can someone please tell me how I can overcome this problem.
I do know of one solution, which is to create a constructor for the element-type of the arraylist, which takes as parameters all the values of all the fields and initializes the element's values. However, the class structures is often big, thus this would be impractical.
I have less than 2 days to do a few thousand lines of programming, and I have been racking my brain on this for more than an hour! Any help would be much appreciated.
dim tmp as new employee
tmp.Name = txtName.text
tmp.Surname = txtSurname.text
Arraylist1.add(tmp)
...
'do something that calls each element of Arraylist1
Now, the code executes perfectly the first time. The second time I push the button though, it throws a null-reference exception. Upon evaluation it is evident that the arraylist did not add a new object to the arraylist, but instead just modified tmp and moved it to the next position in the arraylist, leaving the preceding arraylist pointer empty.
Thus, after the second click, arraylist(0) is empty and arraylist(1) contains the new object.
Can someone please tell me how I can overcome this problem.
I do know of one solution, which is to create a constructor for the element-type of the arraylist, which takes as parameters all the values of all the fields and initializes the element's values. However, the class structures is often big, thus this would be impractical.
I have less than 2 days to do a few thousand lines of programming, and I have been racking my brain on this for more than an hour! Any help would be much appreciated.