K
K
killman2022-04-13 21:51:05
C++ / C#
killman, 2022-04-13 21:51:05

When compiling, it will give an error "Object reference does not point to an instance of an object." What should I do?

I have a class with data. Data is written from datagridview. There is a form that should receive data (name) from the class and write it to textBox1, but when compiling it gives an error "Object reference does not point to an object instance." on the line label1.Text = info.Name[index]. I write in c# windows forms.

namespace LO3_1
{
    public partial class Form3 : Form
    {

        info info = new info();
        int index;
        public Form3()
        {
            InitializeComponent();
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            textBox1.ForeColor = Color.Black;
            textBox1.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            index = Convert.ToInt32(textBox1.Text);
            label1.Text = info.Name[index];
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Morrowind, 2022-04-13
@killman

Hey!
This means that we are using an object ( let's say info.Name[index] ) was not created\initialized or passed by a reference from outside to this code scope.
Easier: You didn't create or don't get the used object. Where? I have no idea. You didn't show the error code itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question