I am new to VB programming. I recently copied a code from internet, which gives me an error of Object Reference Not Set To Instance Of Object, NULL POINTER EXCEPTION. I couldn't understand where the problem lies..!! Help..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If My.Settings.Names Is Nothing Then
        If TextBox1.Text = "" Or TextBox2.Text = "" Then
            MsgBox("Must Fill all Fields")
        Else
            Dim name As String = TextBox1.Text
            Dim number As String = TextBox2.Text
            My.Settings.Names.Add(name + " :: " + number)
            My.Settings.Save()
            Me.Close()
        End If
    Else
        If TextBox1.Text = "" Or TextBox2.Text = "" Then
            MsgBox("Must Fill all Fields")
        Else

            My.Settings.Names.Add(TextBox1.Text + " :: " + TextBox2.Text) /*ERROR COMES HERE*/

            My.Settings.Save()
            Me.Close()
        End If
    End If
    TextBox1.Clear()
    TextBox2.Clear()
    Form1.ListBox1.Items.Clear()
    For Each Name As String In My.Settings.Names
        Form1.ListBox1.Items.Add(Name)
    Next
End Sub

Recommended Answers

All 2 Replies

But I'll take a guess. Go to the Settings area of your project properties. I suspect the problem is that you do not have a Settings variable defined with the name "Names" and of the type "Collection".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.