5
Answers

Object reference not set to an instance of an object.

Ask a question

why I am getting following error for below code :-

      Object reference not set to an instance of an object.

at InterviewTest.Form1.Button1_Click(Object sender, EventArgs e) in h:\visual studio 2010\Projects\InterviewTest\InterviewTest\Form1.vb:line 8

 

 
1. Public Class Form1

2.

3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

4. Dim classOfService As New ClassOfService

5. Dim travelInformation As New TravelInformation

6.

7. classOfService.code = "GT"

8. travelInformation.classes.Add(classOfService)

9. classOfService.code = "HIK"

10. travelInformation.classes.Add(classOfService)

11. TextBox1.Text = travelInformation.classes(1).code

12. End Sub

13. End Class

14.

15. Public Class TravelInformation

16. Public Property classes As List(Of ClassOfService)

17. End Class

It basically means we are trying to pull something out of nothing.am I correct , as we don't have following stuff in the code triggered at nterviewTest.Form1.Button1_Click

Answers (5)